Calculating distance from GPS data

by Edward Sargisson.

GPS Data

Garmin devices record a route as a series of GPS fixes. Each fix records latitude in degrees, longitude in degrees and altitude in meters. Garmin devices also optionally include other information such as distance, speed from a footpod or heart rate from a heart rate sensor.


Unfortunately, athletes don't think in degrees and the length of a degree of longitude changes depending on how close you are to a pole. Ignoring elevation, there are two methods we could use to find the distance in metres between two points. The first method is to project the points to become a flat map and measure the distance there. The second method is to measure the distance across the Earth's sphere.


GPS Data can be projected onto a flat plane that can be used as a map. The standard world map used in every classroom is prepared this way using the Mercator projection. However, this projection isn't very useful for athletes because it distorts distance and it distorts distance more as the position gets closer to the pole. This makes it especially bad for athletes in Canada!

World Map in Mercator Projection

The distortion problem can be partially fixed by using the Universal Transverse Mercator coordinate system. This coordinate system maps the world into 60 zones and defines a Mercator project for each zone. This means that the distortion is much less compared to the full world map project but that the distortion is at its greatest at the edge of the zone. This does work - we do get usable distances in metres - but this coordinate system was designed for soldiers who didn't want to do complex trigonometry in the field.

The Earth is round!

The Earth is round; well actually it's a sphere; well actually it's a lumpy chunk of rock which we approximate with a geometric shape called an oblate spheroid. A spheroid is a flattened sphere which approximates the shape of the Earth. The distance between two points travelling across the surface of the spheroid can be found using several alternative formulas such as Haversine or Vincenty's.


So, using a spheroid method, we can accurately calculate the distance between two points. However, these methods calculate the distance at sea level and completely ignore elevation. As a trail runner, I find this rather annoying: if I'm going straight up the side of a mountain then I want the credit for that distance even if I only went a few hundred metres measured at sea level. With the GPS data we get from a Garmin device we do get elevation. This means that we can model this as a triangle and use the Pythagorean formula. The spheroid formulas above give us the distance at the base of the triangle; the elevation data gives us the side of the triangle and we can then calculate the distance of the hypotenuse. However, the elevation data we get from a Garmin device simply isn't that reliable. In order to calculate the elevation the device needs to get information from more satellites. However, when we're on trails we have the problems of being under trees for much of the time (which makes it more difficult to receive a signal) and we often have a mountain on one side (which makes it impossible to receive a signal).

What does do?

We present two distances: the sea level distance and the slope distance. The sea level distance is calculated, ignoring elevation completely, using Vincenty's algorithm. The slope distance includes elevation and is calculated by transforming the latitude and longitude in degrees into a geocentric co-ordinate system. This is a co-ordinate system which views the Earth as a simple three-dimensional graph with the origin in the centre of the Earth. The co-ordinate system pretends the Earth has stopped rotating so that the same place has the same co-ordinate. We can then calculate the distance using Pythagoras. Note that, if we're ignoring elevation then this would lead to the wrong results because the line would cut straight through the earth. However, the Garmin devices give us very frequent fixes so each fix will be on the Earth's surface and we get a reliable result. However, this result is reliant on the accuracy of the elevation in the GPS data. Because GPS devices are not very accurate with elevation the slope distance cannot be considered accurate.

Contact us at info - at -