geodesy-haversine
v2.1.0
Published
Great-circle distance, initial bearing, midpoint and destination point on a sphere via the haversine formula.
Maintainers
Readme
geodesy-haversine
Great-circle geodesy on a spherical earth: distance, initial bearing, midpoint, destination point, and total path length. Dependency-free ESM.
Coordinates are { lat, lon } in decimal degrees. Distances are in
kilometres by default; pass a radius to switch units.
import { distance, bearing, destination, pathLength } from 'geodesy-haversine';
const london = { lat: 51.5074, lon: -0.1278 };
const paris = { lat: 48.8566, lon: 2.3522 };
distance(london, paris); // ~343 km
distance(london, paris, 3958.8); // ~213 miles (miles radius)
bearing(london, paris); // initial azimuth, degrees
destination({ lat: 40, lon: -75 }, 90, 100); // 100 km due east
pathLength([london, paris]); // total across a polylineAccuracy
The haversine formula assumes a sphere. Real-world error versus an ellipsoidal model (Vincenty / WGS-84) is up to roughly 0.5%. If you need survey-grade accuracy, use an ellipsoidal solver instead. For routing, proximity, and "how far is it" answers this is plenty.
EARTH_RADIUS_KM is the WGS-84 authalic mean radius, 6371.0088.
License
This is free and unencumbered software released into the public domain
(Unlicense). See LICENSE.
