Skip to content

Instantly share code, notes, and snippets.

@henryrossiter
Last active May 5, 2020 15:22
Show Gist options
  • Save henryrossiter/387df68b6f174565857a8938415fddab to your computer and use it in GitHub Desktop.
Save henryrossiter/387df68b6f174565857a8938415fddab to your computer and use it in GitHub Desktop.
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