Created
March 20, 2019 10:22
-
-
Save ostgals/bd52f248bea51b878ae616d6900c0a90 to your computer and use it in GitHub Desktop.
Spherical distance on Earth
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
// credits: http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates | |
function dist(a, b) { | |
const [a0, a1, b0, b1] = [...a, ...b].map(x => x / 180 * Math.PI); | |
const { acos, sin, cos } = Math; | |
return acos(sin(a0) * sin(b0) + cos(a0) * cos(b0) * cos(a1 - b1)) * 6371; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment