Calculate distance between coordinates using the haversine formula.
The haversine formula is numerically stable for short distances, where the simpler spherical law of cosines loses precision through catastrophic cancellation. That stability is why it is the standard choice. Using the law of cosines for nearby points can produce errors of tens of metres or fail entirely, which matters for anything geofenced.
Haversine Distance
a = sin²(Δlat/2) + cos(lat₁)cos(lat₂)sin²(Δlon/2); distance = 2R·atan2(√a, √(1−a))
a = sin²(Δlat/2) + cos(lat₁)cos(lat₂)sin²(Δlon/2); distance = 2R·atan2(√a, √(1−a)) The haversine formula is numerically stable for short distances, where the simpler spherical law of cosines loses precision through catastrophic cancellation. That stability is why it is the standard choice.
Using the law of cosines for nearby points can produce errors of tens of metres or fail entirely, which matters for anything geofenced.
This calculator takes 4 inputs: First latitude, First longitude, Second latitude, Second longitude. The pre-filled defaults are a realistic starting point — replace them with figures from your own environment for a result you can act on.