How to calculate the distance between two GPS coordinates
Two GPS coordinates are just two pairs of numbers â a latitude and a longitude each â and it is tempting to treat the distance between them like any other pair of points on a grid: find the difference in each coordinate, square them, add them, take the square root. That shortcut is wrong, and not by a rounding error either. Latitude and longitude are angles measured on a sphere, not positions on a flat plane, and the actual distance calculation has to account for that from the first step.
The short answer
The standard way to turn two latitude/longitude pairs into a distance is a great-circle formula â the haversine formula is the one most trail and mapping software actually uses â which treats the two points as sitting on the surface of a sphere and works out the shortest arc between them along that surface, then multiplies by the Earth's radius to get an actual distance. It takes both coordinates in radians, runs them through a fixed sequence of trigonometry, and returns a straight-line distance between the two points â not a distance along any trail or road connecting them, just the direct gap between one spot and the other.
Why the flat-map shortcut falls apart
A degree of latitude covers roughly the same distance everywhere on Earth â about 111 kilometres. A degree of longitude does not: it covers about 111 kilometres at the equator and shrinks toward zero as you approach either pole, because lines of longitude converge there. Treat both the same way, as if a degree of one equals a degree of the other, and a calculation done anywhere outside the tropics starts drifting from the true distance â by a little at low latitudes, by a lot further north or south. The Pythagorean shortcut assumes a flat grid where a degree is a degree in every direction, and that assumption simply is not true of latitude and longitude.
A great-circle formula sidesteps the problem by never treating the coordinates as grid positions in the first place. It works directly with the angles, on the curved surface they actually describe, so it does not need a separate correction for how far north or south the points happen to be.
What the calculation actually needs
Every version of the formula starts from the same four numbers: the latitude and longitude of the first point, and the latitude and longitude of the second, each converted from degrees to radians before anything else happens. From there it is a fixed sequence of sine, cosine and arctangent operations that produces a single angle â the angular distance between the two points as seen from the centre of the Earth. Multiplying that angle by the Earth's mean radius turns it into an actual distance, in whichever unit the radius was given in.
None of this needs anything beyond the two coordinate pairs themselves. It does not need the points in between, it does not need altitude, and it does not need to know what lies on the ground between them â it is purely a function of two positions on a sphere.
For two points close together, a shortcut is fine
Full spherical trigonometry matters most over long distances, where the Earth's curvature between the two points is large enough to matter. Two consecutive points on a trail â a few metres apart, recorded a couple of seconds apart â sit close enough together that the patch of Earth between them is, for practical purposes, flat. A simpler flat-plane approximation, correcting only for how much a degree of longitude is worth at that particular latitude, gets close enough to the great-circle answer at that scale that the difference is smaller than the GPS receiver's own uncertainty. This is the version a lot of trail-recording software actually runs, point to point, because it is cheaper to compute and loses nothing worth keeping at hiking distances.
This is what a hike's total distance actually is
A recorded route is not one distance calculation â it is this same two-point calculation run between every consecutive pair of points in the track, with all of the individual results added together. A hike logged once a second for an hour has around 3,600 points and very nearly that many small distance calculations chained end to end, each one covering a few metres. The total distance at the end of the hike is simply the sum of all of them, which is also why it is a running total rather than a single measurement taken once: it only exists once every pair of consecutive points has been through the same calculation.
It is also, by the same logic, a flat distance rather than a sloped one, since the formula works from latitude and longitude alone and never looks at altitude. A steep climb and a flat walk covering identical coordinates come out to the same distance, because nothing about the calculation reads elevation in the first place.
Things that trip people up
- Subtracting two coordinates directly and treating the result as a distance â a difference in degrees is an angle, not a distance, and converting it correctly depends on where on Earth the points are.
- Using the Pythagorean theorem on raw latitude and longitude â this only holds on a flat plane, and latitude/longitude describe positions on a sphere, so the error grows the further the points are from the equator.
- Forgetting to convert degrees to radians before running the trigonometry â most implementations of the formula expect radians, and feeding in raw degrees produces a number that looks plausible but is not the real distance.
- Expecting the result to include elevation â a great-circle distance is measured across the surface, the same flat convention a hike's total distance uses, so a steep and a level route between the same two points measure identically.
Where TrailCam fits in
TrailCam runs this same point-to-point calculation continuously while a route is recording, adding each small distance to the running total shown during the hike. The GPX 1.1 export carries the raw latitude, longitude and altitude for every recorded point, unrounded, so the same distance figure can be recomputed independently from the file itself if you ever want to check it by hand. GPX export is part of the optional TrailCam Pro upgrade; the app itself is free to download.
Questions
- What is the most common formula for GPS distance calculations?
- The haversine formula is the one most trail, mapping and GIS software uses. It treats both coordinates as points on a sphere and returns the great-circle distance between them â the shortest path across the surface, not a straight line through the ground.
- Can I just subtract two latitude/longitude pairs to get the distance?
- No. The difference between two coordinates is an angle, and converting that angle into an actual distance depends on where on Earth the points are, because a degree of longitude covers less real distance the further it is from the equator.
- Does the distance between two GPS coordinates account for elevation change?
- Not by default. A standard great-circle calculation works from latitude and longitude alone, which is also why a hike's total recorded distance is a flat, horizontal figure rather than one that grows on a steep climb.
Recording your own routes
TrailCam is an iPhone app that records your route with GPS, keeps video clips, photos and voice notes pinned to the spot where you took them, and exports the result as GPX 1.1 or CSV. It is free to download.