Haversine Distance

Decision Sciences
Introduced by
Roger Sinnott
Year
1984
Type
Great-circle distance metric
Family
Geographic distance

What does it do?

Haversine distance gives the great-circle distance between two points on a sphere from their latitude and longitude.

Roger Sinnott popularized the haversine form in a 1984 article, and it is widely used to estimate distances along Earth's surface. The result ranges from 0 (identical points) to half the circumference of the sphere.

The intuition behind the method

Imagine two cities on a globe. The shortest path between them along the surface is an arc of the great circle that joins them, much like a rubber band stretched over the sphere. Haversine distance computes the length of that arc. Because it accounts for the sphere's curvature, it is more appropriate than a flat-plane distance for locations far apart. Two nearby cities have a small haversine distance, while cities on opposite sides of the globe have a distance close to half the circumference.

History

The formula is named after the haversine function, a long-established term in spherical trigonometry. Roger Sinnott's 1984 Sky and Telescope article, 'Virtues of the haversine', promoted the haversine form as a numerically preferable alternative to the law of cosines for spherical distance. The formula is now widely implemented in mapping and location software.

When to use it

Haversine distance suits geographic work where the Earth can be modelled as a sphere, such as mapping, geolocation, proximity searches and spatial analysis, where the distance is needed between two latitude/longitude points. Use it when moderate accuracy and speed are sufficient. Do not use it when the required quantity is road or route distance, travel time, or the distance between points given in a local Cartesian or projected system. Where ellipsoidal precision matters, for example for very long distances or work near the poles, consider the Vincenty distance, which models the Earth as an ellipsoid.

Limitations and considerations

  • It assumes a spherical Earth and ignores the ellipsoidal shape and local terrain, so its error relative to an ellipsoidal model is systematic and depends on location and distance.
  • The approximation error depends on distance and location, which is why an ellipsoidal method such as Vincenty is preferred when high precision is needed.
  • It is defined only for latitude and longitude on a sphere; it cannot be applied directly to points in non-geographic or projected coordinate systems.
  • It ignores altitude, so it gives the surface distance between two points and not their 3D separation.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Numerically stable for small separations: the haversine form avoids the rounding problems that the law-of-cosines expression has when two points are close together.
  • Direct geographic meaning: the result is the length of the arc along the Earth's surface between the two points, which is easy to interpret for mapping tasks.
  • Low computational cost: a single pass of basic trigonometric operations, with no iteration, which is why it is common in location software.
  • Wide implementation: it is available in many mapping and location libraries and in statistical packages (for example, the fossil package in R provides haversine distances).

Applications

  • Mapping and navigation: calculating distances between cities, landmarks and route waypoints.
  • Location-based services: finding nearby restaurants, stores or other services within a given radius.
  • Geospatial clustering: grouping locations by proximity for region definition or analysis.
  • Logistics planning: providing straight-line great-circle distances as an input to, but not a substitute for, route-based travel time estimates.
  • Epidemiology and public health: measuring geographic distance for analyses of facility coverage and spatial spread.

How it works

How it works

1

Convert each latitude and longitude from degrees to radians, because the trigonometric functions in the formula expect radians.

Formula
\varphi_{\mathrm{rad}} = \varphi_{\mathrm{deg}}\cdot\frac{\pi}{180},\quad \lambda_{\mathrm{rad}} = \lambda_{\mathrm{deg}}\cdot\frac{\pi}{180}
2

Compute the haversine a = sin²(Δφ/2) + cos φ1 · cos φ2 · sin²(Δλ/2), where φ is latitude and λ is longitude, then take the central angle c = 2·atan2(√a, √(1−a)). The value c is the angle, in radians, subtended at the sphere's centre by the two points.

Formula
a = \sin^2\!\left(\frac{\Delta\varphi}{2}\right) + \cos\varphi_1\cos\varphi_2\,\sin^2\!\left(\frac{\Delta\lambda}{2}\right),\quad c = 2\,\mathrm{atan2}\!\left(\sqrt{a},\sqrt{1-a}\right)
3

Multiply c by the sphere's radius, for example 6371 km (mean Earth radius) or 3959 miles, to obtain the distance in that unit: d = R · c.

Formula
d = R\cdot c

Common pitfalls

  • Using degree values directly in the trigonometric functions. The inputs must be converted to radians first, or the output is meaningless.
  • Confusing great-circle distance with the straight-line chord through the Earth. The chord is shorter; the great-circle distance is the arc along the surface and is never shorter than the chord.
  • Treating the result as the travel distance. It is the straight arc between two points on the sphere and ignores roads, routes, obstacles and terrain.
  • Using a radius in one unit and expecting the output in another. For example, 6371 km gives kilometres, and 3959 miles gives miles.
  • Applying haversine to projected coordinates such as UTM, where planar distance is the appropriate measure.

Frequently asked questions

How accurate is haversine distance?

Haversine assumes a sphere, so its error relative to the real Earth, which is an oblate spheroid, is systematic and depends on location and distance. It is usually adequate for mapping and proximity tasks. When higher precision is required, use the Vincenty distance formula.

What Earth radius should I use?

The commonly used value is 6371 km (mean radius). Equatorial radius is 6378 km, polar radius is 6357 km. For most applications, the mean radius is appropriate; use equatorial or polar for high-precision work in specific regions.

Can haversine handle wrap-around at the date line or poles?

Yes. The formula depends on the sine and cosine of the coordinate differences, which are periodic, so longitude wrapping at ±180° does not need special treatment and the result is the shortest arc. Points at the poles are also handled, but the choice of radius still matters for the unit of the result.

Is haversine faster than Vincenty distance?

Yes. Haversine uses a single pass of simple trigonometric operations, while Vincenty is an iterative method and is slower. Vincenty's iteration can also fail to converge for nearly antipodal points, where a fallback is needed. Choose haversine when speed and moderate accuracy are sufficient, and Vincenty when ellipsoidal precision matters more than speed.

Sources

  1. Sinnott, R. W. (1984). Virtues of the haversine. Sky and Telescope, 68(2), 159.

    Open publication reference
  2. Tobler, W. (1980). Numerical map generalization. In Proceedings of the Ninth International Cartographic Association Conference (pp. 280-286).

    Open publication reference