How to use java code to find the distance between two Zipcodes?

My request is similar to this question, except for the fact that I am prohibited from using latitude and longitude values I want to calculate the "walk" distance between two zip codes Later, I also need to query "who is in X kms?"

I don't know if it can be realized Can you really find the distance between two given postal codes? I don't want an answer that applies only to us / UK zip codes I need a generic solution that will apply to any two zip codes in the world

If the calculation of distance does not use langitude & longitude, it is impossible to obtain the langitude / longitude value of a given zipcode? (Amazing) but how?

Any tutorials / examples will be very helpful Because I'm working on a commercial project, I can't use the Google Maps API So please do not suggest any other licensed services

Thank you in advance,

One of the answers to the update this question suggests using MySQL or postgress... Will it work for me?

Solution

If you are interested, here is my java implementation of haverse formula

/**
 * Calculates the distance in km between two lat/long points
 * using the haversine formula
 */
public static double haversine(
        double lat1,double lng1,double lat2,double lng2) {
    int r = 6371; // average radius of the earth in km
    double dLat = Math.toradians(lat2 - lat1);
    double dLon = Math.toradians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
       Math.cos(Math.toradians(lat1)) * Math.cos(Math.toradians(lat2)) 
      * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.atan2(Math.sqrt(a),Math.sqrt(1 - a));
    double d = r * c;
    return d;
}

I hereby donate to GPL in public places

The above is collected by programming house for you. How to use java code to find the distance between two Zipcodes? I hope this article can help you solve how to use java code to find the distance between two Zipcodes? Program development problems encountered.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>