展开全部
public static double geo_distance(double lat1, double lng1, double lat2,
double lng2) {
// earth's mean radius in KM
double r = 6378.137;
lat1 = Math.toRadians(lat1);
lng1 = Math.toRadians(lng1);
lat2 = Math.toRadians(lat2);
lng2 = Math.toRadians(lng2);
double d1 = Math.abs(lat1 - lat2);
double d2 = Math.abs(lng1 - lng2);
double p = Math.pow(Math.sin(d1 / 2), 2) + Math.cos(lat1)
* Math.cos(lat2) * Math.pow(Math.sin(d2 / 2), 2);
double dis = r * 2 * Math.asin(Math.sqrt(p));
return dis;
}
public static double geo_distance(double lat1, double lng1, double lat2,
double lng2) {
// earth's mean radius in KM
double r = 6378.137;
lat1 = Math.toRadians(lat1);
lng1 = Math.toRadians(lng1);
lat2 = Math.toRadians(lat2);
lng2 = Math.toRadians(lng2);
double d1 = Math.abs(lat1 - lat2);
double d2 = Math.abs(lng1 - lng2);
double p = Math.pow(Math.sin(d1 / 2), 2) + Math.cos(lat1)
* Math.cos(lat2) * Math.pow(Math.sin(d2 / 2), 2);
double dis = r * 2 * Math.asin(Math.sqrt(p));
return dis;
}