2个latlon点之间的距离
问题描述:
我想确定2个latlon点之间的距离。 简单距离公式http://www.purplemath.com/modules/distform.htm不正确,因为我们正在处理2种不同的度量(经度和纬度)。2个latlon点之间的距离
有没有解决这个问题的标准方案?
答
试试这个, 这里使用了“半正矢”的公式计算出两点间的大圆距离 - 也就是,在地球表面的最短距离 - 给人一种“原样两只鸟之间的距离(忽略任何山丘!)。
半正矢式:
R = earth’s radius (mean radius = 6,371km)
Δlat= lat2- LAT1 Δlong= long2- long1 一个=sin²(Δlat/ 2)+ COS(LAT1)名为.cos(LAT2).sin²(Δlong/ 2 ) C = 2.atan2(√A,√(1-α)) d = RC
答
尝试此JavaScript半正矢函数沿着torad()辅助功能,我使用的为我的地图应用程序
function calculateHaversineDistance(lat1x, lon1, lat2x, lon2) {
var R = 6371; // km
var dLat = toRad(lat2x-lat1x);
var dLon = toRad(lon2-lon1);
var lat1 = toRad(lat1x);
var lat2 = toRad(lat2x);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
function toRad(x) {
return x * Math.PI/180;
}
希望这会有所帮助。