Distance Calculation: Haversine, Geodesics & When It Matters
Why flat map arithmetic fails over large distances, what the haversine formula does, and when a full ellipsoidal geodesic is the better choice.
Why flat map arithmetic fails over large distances, what the haversine formula does, and when a full ellipsoidal geodesic is the better choice.
- Surveying, legal boundaries and engineering: use the required datum/CRS and professional geodesic or survey methods.
- Aviation and navigation: use domain-specific navigation systems, route constraints and operational data rather than a simple distance calculator alone.
- Web tools, rough logistics estimates and exploratory analysis: a documented spherical approximation is often sufficient when its limits are understood.
On a curved Earth, long-distance surface measurements cannot be treated as ordinary straight-line distances on raw latitude and longitude. The shortest surface route on a sphere follows a great-circle arc; on an ellipsoid, the equivalent problem is solved as an ellipsoidal geodesic.
The haversine formula
Haversine treats the Earth as a sphere and computes the central angle between two latitude/longitude points. Using a mean Earth radius such as 6371.0088 km makes it a practical, numerically stable approximation for many everyday mapping tasks.
The ellipsoidal reference
The Earth is better represented by an oblate ellipsoid than a perfect sphere. High-precision geodesic libraries use an ellipsoid such as WGS84 and algorithms designed for that surface. The difference from a spherical calculation depends on route, latitude and distance; for ordinary web planning it is usually small, but precision work should use an ellipsoidal method.
When the difference matters
- Surveying, legal boundaries and engineering: use the required datum/CRS and professional geodesic or survey methods.
- Aviation and navigation: use domain-specific navigation systems, route constraints and operational data rather than a simple distance calculator alone.
- Web tools, rough logistics estimates and exploratory analysis: a documented spherical approximation is often sufficient when its limits are understood.
Area calculations need the same care. For larger regions, use a geodesic or projection-aware method rather than assuming a latitude/longitude polygon is flat.
Worked example: New York to London
A straight line drawn on a flat Mercator map is not the shortest surface route between New York and London. The great-circle path bends northward on the map because the projection distorts the geometry of the sphere. A haversine calculation works from the latitude and longitude angles directly, producing the spherical surface distance without measuring screen pixels or relying on the map projection.
Why road distance is a different problem
A geodesic answers 'how far apart are these points on the Earth's surface?' A routing engine answers 'how far must a vehicle travel through this transport network?' The road answer depends on bridges, permitted roads, turns, ferries, one-way rules and the network dataset. Comparing the two can be useful: the geodesic is a theoretical lower bound, while the route reflects infrastructure.
Sources of error people often overlook
- The input coordinates may be less accurate than the distance formula.
- A city name may resolve to a centre point that differs from the address or neighborhood you intended.
- A spherical result and an ellipsoidal result are not mathematically identical, especially over long routes.
- Map projection distortion affects visual interpretation even when the underlying distance calculation is correct.
Which method should you choose?
Use a documented spherical great-circle method for everyday worldwide comparisons when sub-percent precision is sufficient. Use ellipsoidal geodesics when the application requires higher geodetic fidelity. Use routing data when roads or travel times are the real question. And for survey, cadastral, engineering or safety-critical work, use the coordinate reference system and professional method required by that domain.
The same two points can have several correct distances
People often ask for 'the distance' as though geography has one universal answer. Between the same two places you can measure a spherical great-circle distance, an ellipsoidal geodesic, a road-network distance, a walking route, a flight itinerary, a nautical route or even a projected planar distance inside a local coordinate system. Each is correct for a different question.
MapBench separates those questions deliberately. Use Distance Between Two Places for straight-line surface separation, Driving Distance when roads matter, and Drive Time Map when accessibility in minutes is the real decision.
What the haversine formula is doing in plain English
Latitude and longitude are angles measured from the Earth's centre and reference meridian. Haversine converts the difference between two pairs of those angles into a central angle on a sphere. Multiply that angle by the chosen Earth radius and you get the length of the corresponding great-circle arc. The formula is popular because it is simple, stable for ordinary inputs and easy to reproduce.
The choice of radius matters slightly because the real Earth does not have one exact spherical radius. A mean radius such as 6,371.0088 km is a documented compromise. If you use a different radius, you should expect a slightly different result even though the formula itself is the same.
Why an ellipsoid changes the answer
Earth is wider around the Equator than pole-to-pole. Ellipsoidal geodesic algorithms account for that flattening and solve the shortest path on the reference ellipsoid rather than on a perfect sphere. The difference is often small enough that a casual user will never notice, but it becomes relevant when distances are long, precision requirements are strict, or the result is being compared with a professional geodesic source.
A good way to sanity-check a result
- Confirm both pins are actually at the intended locations, not just city centroids with similar names.
- Compare miles and kilometres using a known conversion rather than re-running a different method.
- If a road distance is shorter than the straight-line distance, investigate the inputs or routing output; that should not happen for the same endpoints.
- For very short distances, ask whether input-coordinate accuracy is larger than the difference you are trying to measure.
- For global routes, do not judge correctness by the apparent straightness of a line on a Mercator map.
Where local planar distance still makes sense
Not every geographic measurement needs global geodesics. Engineers and GIS analysts often work in a projected coordinate system designed for a particular region. Within its intended area, measuring x/y coordinates on that projection can be accurate and convenient. The key is that the projection is chosen deliberately for the location and scale, not that latitude and longitude are treated like ordinary Cartesian metres.
If the visual appearance of a flat map is causing confusion, the guide on map projections and distortion explains why a route can look curved even when it is the shortest path on the globe.
What to report with the number
A useful distance result should name the method, units and endpoints. '2,440 miles' is less informative than 'approximately 2,440 miles great-circle distance between these selected coordinates using a spherical Earth model.' That sentence tells another person what can and cannot be inferred. Good geographic work is not only about producing a number; it is about making the assumptions visible enough that somebody else can reproduce it.
Continue with the actual map tools
About the author
Aryan Khan edits MapBench with a focus on practical map calculations, coordinate systems, routing concepts, open geographic data and clear limitations. Guides are written to help a reader make a better decision, not just to repeat a definition.
Related reading
How to Calculate Distance Between Two Coordinates
The haversine formula explained step by step, with worked examples in kilometres, miles and nautical miles — and the cases where the spherical answer is not good enough.
Why Does Greenland Look Bigger Than Africa?
On most world maps Greenland looks as big as Africa. It is actually 14x smaller. Here is the Mercator illusion explained.
Largest US Counties by Area
The 30 largest US counties by land area, led by Alaska's Yukon-Koyukuk. Ranked table in square miles.
Alaska vs Texas: Size Comparison
Alaska is 2.2x larger than Texas — see the true sizes side by side with real land-area numbers.
Put this topic into practice
These tools link to this resource for background. Each has its own inputs, coverage and limitations; a related method does not mean an identical dataset.
- Drive Time Map
How far you can drive, bike or walk in set minutes — real isochrones.
- Driving Distance Calculator
Road distance and drive time between two places.
- Magnetic Declination Calculator
Calculate date-specific magnetic declination, inclination and field strength for any location using WMM 2025.
- Distance Matrix Calculator
Pairwise great-circle distances between many places — table and CSV export.