public static double algorithm(double lon1, double lat1, double lon2, double lat2) {
/**纬度*/
double tmpLat1 = rad(lat1);
double tmpLat2 = rad(lat2);
/**两点纬度之差*/
double a = tmpLat1 - tmpLat2;
/**经度之差*/
double b = rad(lon1) - rad(lon2);
/**计算两点距离的公式*/
double s = 2 * Math.asin(Math.sqrt(
Math.pow(Math.sin(a / 2), 2) + Math.cos(tmpLat1) * Math.cos(tmpLat2) * Math.pow(Math.sin(b / 2), 2)));
/**弧长乘地球半径(半径为米)*/
s = s * 6378137.0;
/**精确距离的数值*/
s = Math.round(s * 10000d) / 10000d;
return s;
}
private static double rad(double d) {
/**角度转换成弧度*/
return d * Math.PI / 180.00;
}
计算两点之间距离
于 2022-06-17 11:09:24 首次发布