function getDistance(lng1,lat1,lng2,lat2){
var radLat1 = lat1 * Math.PI / 180.0
var radLat2 = lat2 * Math.PI / 180.0
var a = (lat1 - lat2) * Math.PI / 180.0;
var b = (lng1 - lng2) * Math.PI / 180.0;
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 * 6378137 ;// 地图半径;
s = Math.round(s * 10000) / 10000;
console.log(s);
return s
}
javascript根据经纬度计算两点之间的距离
最新推荐文章于 2024-10-08 10:32:18 发布