latLng_calc_distance(arrs) { // 经纬度数据算距离
let sum = 0
const l = arrs.length
function Rad(d) {
return d * Math.PI / 180.0
}
for (let i = 0, le = l - 1; i < le; i++) {
const radLat1 = Rad(arrs[i]['lat'])
const radLat2 = Rad(arrs[i + 1]['lat'])
const lats = radLat1 - radLat2
const lngs = Rad(arrs[i]['lng']) - Rad(arrs[i + 1]['lng'])
const s = [2 * Math.asin(Math.sqrt(Math.pow(Math.sin(lats / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(lngs / 2), 2)))] * 6378.137
sum = sum + s
}
return sum
},
const arrs =
[{ 'lat': 23.119180000000004, 'lng': 113.36309000000001 },
{ 'lat': 23.11889, 'lng': 113.36321000000001 },
{ 'lat': 23.11905, 'lng': 113.36389000000001 },
{ 'lat': 23.119310000000002, 'lng': 113.36439000000001 }]
这样计算出来的路径,和谷歌地图上预算出来的路径相差不大