Last active
October 15, 2022 18:10
-
-
Save zazaulola/070a519fd2587ab08f77a09a910d0579 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 geodistance(lat1,lon1,lat2,lon2){ | |
const R = 6371e3; // in metres | |
const φ1 = lat1 * Math.PI/180; // φ, λ in radians | |
const φ2 = lat2 * Math.PI/180; | |
const Δφ = (lat2-lat1) * Math.PI/180; | |
const Δλ = (lon2-lon1) * Math.PI/180; | |
const a = Math.sin(Δφ/2) * Math.sin(Δφ/2) + | |
Math.cos(φ1) * Math.cos(φ2) * | |
Math.sin(Δλ/2) * Math.sin(Δλ/2); | |
const c = 2 * Math.atan2(a**.5, (1-a)**.5); | |
const d = R * c; // in metres | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment