Why flat distance is wrong
The Earth is roughly a sphere, so the shortest path between two points follows a great circle, a circle whose center is the center of the Earth. Treating latitude and longitude as if they were flat plane coordinates overstates or understates real distance, badly near the poles where longitude lines crowd together.
The common formula
The haversine formula computes great circle distance from two latitude and longitude pairs using the Earth radius. It is numerically stable for the small and large angles that show up in real apps, which is why it is the usual choice.
When to use which
- Exact ranking. Use great circle distance to rank candidates after a coarse spatial lookup.
- Cheap filtering. A flat approximation can be fine for tiny radii where curvature barely matters, saving computation.
- Routing. Note that great circle distance is a straight line over the globe, not the driving distance along roads.
Key idea
Great circle distance measures the true shortest path over a sphere, which is the correct way to rank proximity rather than flat plane math.