getDistance(lat1, lng1, lat2, lng2) { let radLat1 = lat1 * Math.PI / 180.0; let radLat2 = lat2 * Math.PI / 180.0; let a = radLat1 - radLat2; let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0; let 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 * 6378.137; s = Math.round(s * 10000) / 10000; let distance = s.toString(); let distance_str = ""; distance = distance.substring(0, distance.indexOf('.') + 2); if (parseInt(distance) >= 1) { distance_str = distance + "km"; return distance_str } else { distance_str = (distance * 1000) + "m"; return distance_str } },
标签:distance,180.0,经纬度,js,let,str,两点,PI,Math From: https://www.cnblogs.com/changshu/p/17136329.html