Tool to calculate the Haversine distance between two geographic points using their GPS coordinates (latitude, longitude). Easily compare distances in kilometers, miles, or nautical miles.
Haversine Distance - dCode
Tag(s) : Geography
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
The Haversine distance (short for half of a versed sine) refers to the length of the great-circle arc between two points on the surface of a sphere, often the Earth, taking into account its curvature.
It is based on the Haversine formula, a trigonometric equation that provides a precise estimate measurement of the distance between two GPS coordinates (latitude and longitude).
The Haversine formula calculates the great-circle distance between two points on the Earth's surface, given their GPS coordinates expressed in latitude and longitude.
It relies on spherical trigonometry to account for the curvature of the Earth's sphere.
From two points $ P_1 ( \varphi_1, \lambda_1 ) $ and $ P_2 ( \varphi_2, \lambda_2 ) $, expressed in radians.
The Haversine formula is: $$ d = 2r \cdot \arcsin\left( \sqrt{ \sin^2\left( \frac{\varphi_2 - \varphi_1}{2} \right) + \cos(\varphi_1)\cos(\varphi_2)\sin^2\left( \frac{\lambda_2 - \lambda_1}{2} \right) } \right) $$
where $ r $ is the radius of the reference sphere (the average radius of the Earth is approximately 6371 km)
Example: The distance between two antipodal points at opposite ends of the Earth is approximately 20015 km (whereas in a straight line, passing through the center of the Earth, the distance would be 12742 km).
Using the Haversine distance allows the user to measure the actual distance between two geographic locations without being limited to a planar (Euclidean) distance.
The classic Euclidean distance measures a straight path on a plane, ignoring the Earth's curvature. The Haversine distance calculates the shortest path along the Earth's sphere.
It is a method commonly used in air navigation, geodetic calculations, GPS mapping, and mobile geolocation applications.
Several geodetic formulas exist for calculating distances on Earth:
— Vincenty: more precise, based on an ellipsoidal model of the Earth.
— Great-circle distance: a simplified version of the great-circle calculation without using the haversine function.
— Equirectangular approximation: a faster but less precise method, suitable for small distances.
Each variant offers a compromise between calculation speed and accuracy depending on the intended use.
The Haversine formula was introduced in the 19th century based on the work of James Inman (1835), a British mathematician. It derives from the Haversine tables used in astronomy and navigation to simplify trigonometric calculations before the advent of calculators and computers.
dCode retains ownership of the "Haversine Distance" source code. Any algorithm for the "Haversine Distance" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Haversine Distance" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Haversine Distance" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Haversine Distance" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Haversine Distance on dCode.fr [online website], retrieved on 2025-12-19,