标签:
function getGreatCircleDistance(lat1,lng1,lat2,lng2){
if(!lat1 || !lng1 || !lat2 || !lng2){
return -1;
}
var v = 0;
var radLat1 = getRad(lat1);
var radLat2 = getRad(lat2);
var a = radLat1 - radLat2;
var b = getRad(lng1) - getRad(lng2);
var 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);
if(s<1000){
v = s.toFixed(0) + ‘m‘;
}
else{
s = s / 1000;
v = s.toFixed(1) + ‘km‘;
}
return v;
}
var lat1 = //当前纬度
var lng1 = //当前经度
var lat2 = //目标纬度
var lng2 = //目标经度
v = getGreatCircleDistance(lat1,lng1,lat2,lng2)
更加比较详细的网址:http://www.360doc.com/content/10/1228/10/284485_81937345.shtml
根据两点经纬度计算距离
标签:
原文地址:http://www.cnblogs.com/mrjie/p/4175472.html