2012-05-02 175 views

回答

0

看看這個:http://www.zipcodeworld.com/samples/distance.java.html

由於上述鏈接斷開看看這個:Calculate distance between two latitude-longitude points? (Haversine formula)

這篇文章的摘要:

public final static double AVERAGE_RADIUS_OF_EARTH = 6371; 
public int calculateDistance(double userLat, double userLng, double venueLat, double venueLng) { 

    double latDistance = Math.toRadians(userLat - venueLat); 
    double lngDistance = Math.toRadians(userLng - venueLng); 

    double a = (Math.sin(latDistance/2) * Math.sin(latDistance/2)) + 
        (Math.cos(Math.toRadians(userLat))) * 
        (Math.cos(Math.toRadians(venueLat))) * 
        (Math.sin(lngDistance/2)) * 
        (Math.sin(lngDistance/2)); 

    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 

    return (int) (Math.round(AVERAGE_RADIUS_OF_EARTH * c)); 

} 
+0

鏈接不工作了。 –

+0

Java回答:http://stackoverflow.com/a/12600225/1308743 – Kyle