Straight-line vs road distance: why haversine underestimates
The haversine formula gives distance as the crow flies, not as the car drives. When that's fine, when it costs you money, and how to get real road distance.
By Wayline Engineering · · Updated · 1 min read
The haversine formula computes the great-circle distance between two coordinates — the distance "as the crow flies." It's fast, free and runs anywhere. It also systematically underestimates how far a vehicle has to travel.
Where haversine is good enough
- Pre-filtering candidates before an exact calculation.
- Clustering and rough heatmaps.
- Sorting things that are all far apart in open terrain.
Where it costs you
- Delivery fees and shipping rates — you under-charge long, winding trips.
- Mileage reimbursement — employees are under-reimbursed.
- ETAs and service windows — customers wait longer than promised.
Why roads are longer
Roads follow terrain and property lines, cross rivers only at bridges, and one-way systems force loops. The ratio between road and straight-line distance (the detour index) varies by city and by trip. That variability is the real problem: you can't fix it with a constant multiplier.
Getting real road distance
curl "https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial" \
-H "Authorization: Bearer $WAYLINE_API_KEY"The Distance API returns road distance and drive time computed on OpenStreetMap roads. Each page of our distance calculator also shows the straight-line distance and the detour percentage for real city pairs.
Use both
Use haversine to narrow the field, then road distance for anything that affects money or promises. That keeps API usage — and cost — low.
Draft for review: add a chart of detour index distribution from computed city pairs once city-pairs.json is generated.