Skip to content

Instantly share code, notes, and snippets.

@M-erb
Forked from manix/calculate geometric euclidean distance
Created August 10, 2019 21:39
Show Gist options
  • Save M-erb/7ec13e6ae02597488abe10569841b282 to your computer and use it in GitHub Desktop.
Save M-erb/7ec13e6ae02597488abe10569841b282 to your computer and use it in GitHub Desktop.
Distance between points simplified
getDistanceFromLatLonInM(lat1, lon1, lat2, lon2) {
var a =
Math.pow(Math.sin(deg2rad(lat2 - lat1) / 2), 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.pow(Math.sin(deg2rad(lon2 - lon1) / 2), 2);
return 12742000 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment