Last active
May 5, 2020 15:22
-
-
Save henryrossiter/387df68b6f174565857a8938415fddab 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 haversineDistanceBetweenPoints(lat1, lon1, lat2, lon2) { | |
const R = 6371e3; | |
const p1 = lat1 * Math.PI/180; | |
const p2 = lat2 * Math.PI/180; | |
const deltaLon = lon2 - lon1; | |
const deltaLambda = (deltaLon * Math.PI) / 180; | |
const d = Math.acos( | |
Math.sin(p1) * Math.sin(p2) + Math.cos(p1) * Math.cos(p2) * Math.cos(deltaLambda), | |
) * R; | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment