Created
November 23, 2016 11:00
-
-
Save yourtion/805e38771977e0ad9d4a1e9358b4379b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDistance(lat1, lng1, lat2, lng2) { | |
var dis = 0; | |
var radLat1 = toRadians(lat1); | |
var radLat2 = toRadians(lat2); | |
var deltaLat = radLat1 - radLat2; | |
var deltaLng = toRadians(lng1) - toRadians(lng2); | |
var dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2))); | |
return dis * 6378137; | |
function toRadians(d) { return d * Math.PI / 180;} | |
} | |
console.log(getDistance(39.54, 116.23, 38.85, 115.48)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment