您的位置:首页 > 其它

计算两点经纬度之间的算法

2012-03-05 16:37 295 查看
private static final double EARTH_RADIUS = 6378.137;

private static double rad(double d) {
return d * Math.PI / 180.0;
}

/**
* 得出两个经纬度之间的距离
*
* @param r_longitude
* @param r_latitude
* @param n_longitude
* @param n_latitude
* @return 距离
*/
public static double getDistanceByLanLon(double r_longitude,
double r_latitude, double n_longitude, double n_latitude) {
double radLat1 = rad(r_latitude);
double radLat2 = rad(n_latitude);
double a = radLat1 - radLat2;
double b = rad(r_longitude) - rad(n_longitude);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(radLat1) * Math.cos(radLat2)
* Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
return s;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: