Skip to content

Instantly share code, notes, and snippets.

@ostgals
Created March 20, 2019 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ostgals/bd52f248bea51b878ae616d6900c0a90 to your computer and use it in GitHub Desktop.
Save ostgals/bd52f248bea51b878ae616d6900c0a90 to your computer and use it in GitHub Desktop.
Spherical distance on Earth
// 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