Skip to content

Instantly share code, notes, and snippets.

@ostgals ostgals/dist.js
Created Mar 20, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.