GPS Distance (Haversine)
Great-circle distance between two coordinates, with the bearing you leave on AND the bearing you arrive on.
Example
You enter
- Lat 1 40.7128
- Lon 1 -74.006
- Lat 2 34.0522
- Lon 2 -118.244
You get
- Distance (miles) 2451
Details, formula, and sources
A great circle is the shortest path but it is not a constant heading: the course turns continuously, so the initial bearing is a departure heading rather than something to steer the whole way. New York to Los Angeles leaves on 273.7 degrees and arrives on 245.9, a 27.8 degree swing, which is why a long leg is flown or sailed as a series of shorter rhumb-line legs re-cut along the way. The drift is near zero on a short leg and enormous at high latitude, and it is exactly zero along a meridian, which is itself a great circle.
Great-circle distance via the haversine formula a = sin²(Δφ/2) + cos(φ1) × cos(φ2) × sin²(Δλ/2); d = 2 × R × atan2(sqrt(a), sqrt(1−a)). R = 6371 km mean earth radius. Initial bearing from atan2(sin(Δλ) cos(φ2), cos(φ1) sin(φ2) − sin(φ1) cos(φ2) cos(Δλ)); FINAL bearing is the reverse leg's initial bearing turned 180 degrees, and the drift between them is reported as a signed shortest-angle difference.
Classical spherical trigonometry; WGS84 mean radius.
Haversine / great-circle derivations are free in navigation texts and at nist.gov and university OCW.
Estimate. AHJ and licensed professional govern.
Field names used by the API: lat1, lon1, lat2, lon2, miles
- Earth radius 6371 km (mean spherical) - actual oblate-spheroid distance can differ ≤ 0.5%WGS84 mean radius