1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| function Rad(d) { return (d * Math.PI) / 180.0 }
function GetDistance(lat1, lng1, lat2, lng2) { var radLat1 = Rad(lat1) var radLat2 = Rad(lat2) var a = radLat1 - radLat2 var b = Rad(lng1) - Rad(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 * 6378.137 s = Math.round(s * 10000) / 10 / 1000 return s.toFixed(2) }
|