Created
May 18, 2017 00:07
-
-
Save tlhunter/6bd77b58c823bc0019880110271b883a to your computer and use it in GitHub Desktop.
Get the distance between two points in meters
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(p1, p2) { | |
var radlat1 = Math.PI * p1.lat/180; | |
var radlat2 = Math.PI * p2.lat/180; | |
var theta = p1.lng - p2.lng; | |
var radtheta = Math.PI * theta/180; | |
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta); | |
dist = Math.acos(dist); | |
dist = dist * 180 / Math.PI; | |
dist = dist * 60 * 1.1515 * 1.609344 * 1000; | |
return dist; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment