Home

haversine

The haversine formula is a mathematical method used to calculate the great-circle distance between two points on a sphere from their latitudes and longitudes. It is named for the haversine function, haversin(θ) = sin^2(θ/2), and is widely used in navigation, geospatial computing, and geographic information systems as a convenient way to estimate distances on Earth or other spherical bodies.

To compute the distance, convert the latitudes φ1, φ2 and longitudes λ1, λ2 to radians. Let Δφ =

Limitations include the spherical assumption: the Earth is an oblate spheroid, so the haversine distance is

φ2
−
φ1
and
Δλ
=
λ2
−
λ1.
Then
a
=
sin^2(Δφ/2)
+
cos(φ1)
cos(φ2)
sin^2(Δλ/2).
The
central
angle
between
the
points
is
c
=
2
atan2(
sqrt(a),
sqrt(1
−
a)
),
and
the
distance
is
d
=
R
·
c,
where
R
is
the
sphere’s
radius.
For
Earth,
a
common
choice
is
the
mean
radius
R
≈
6,371
km
(3,959
miles).
Some
implementations
use
d
=
2R
arcsin(
sqrt(a)
)
as
an
alternative
form.
an
approximation,
with
larger
potential
error
over
long
distances.
For
high-precision
work,
ellipsoidal
models
such
as
Vincenty’s
formulae
are
preferred.
The
haversine
formula
remains
popular
for
its
simplicity,
numerical
stability
for
small
distances,
and
ease
of
implementation
in
software.