← Lessons

quiz vs the machine

Gold1320

System Design

Great Circle Distance

Measuring real distance between two points on a sphere instead of on flat paper.

4 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What path does great circle distance follow?

2. How does great circle distance differ from routing distance?