public static double getDistatce(double lon1, double lat1, double lon2, double lat2) {
double R = 6371;
double distance = 0.0;
double dLat = (lat2 - lat1) * Math.PI / 180;
double dLon = (lon2 - lon1) * Math.PI / 180;
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(lat1 * Math.PI / 180)
* Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon / 2)
* Math.sin(dLon / 2);
distance = (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))) * R;
return distance;
}
作为一个静态方法,可以随时调用,用处较少,可以直接放在要用的类中