Bearing and distance calculator
Compute the initial bearing and great-circle distance between two latitude/longitude coordinates.
Initial bearing (A → B)215.0° SW
Great-circle distance434 m
The formula
Great-circle distance (haversine formula):
a = sin²(Δφ/2) + cos φ1 · cos φ2 · sin²(Δλ/2), d = 2R · atan2(√a, √(1−a))
Initial bearing:
θ = atan2(sin Δλ · cos φ2, cos φ1 · sin φ2 − sin φ1 · cos φ2 · cos Δλ)
This is exactly what this site uses to compute distance and bearing to each site on a location page (lib/geo.ts).