Created
December 9, 2017 17:32
-
-
Save steniowagner/c7b2d0aa3dd8b13fbef52dacc9360f46 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
calculateDistanceBetweenCoordinates = (firstCoordinate, secondCoordinate) => { | |
const PI = 0.017453292519943295; | |
var haversine = 0.5 - Math.cos((secondCoordinate.latitude - firstCoordinate.latitude) * PI) / 2 + | |
Math.cos(firstCoordinate.latitude * PI) * Math.cos(secondCoordinate.latitude * PI) * | |
(1 - Math.cos((secondCoordinate.longitude - firstCoordinate.longitude) * PI)) / 2; | |
return 12742 * Math.asin(Math.sqrt(haversine)); // 2 * EARTH_RADIUS (6371); | |
} | |
console.log(calculateDistanceBetweenCoordinates(first, second) * 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment