Guides

Estimate a route's total elevation gain

Total elevation gain is a single number that tells a hiker or cyclist more about a route's difficulty than distance alone ever will. It is also simple to calculate once you have elevation data for enough points along the route.

Getting elevation for the route

Send the route's coordinates, in order, to /v1/elevation, either with the points parameter or as a bulk POST array.

GET /v1/elevation?points=45.8326,6.8652|45.8400,6.8700|45.8475,6.8750|45.8300,6.8800
{
  "status": "ok",
  "results": [
    {"lat": 45.8326, "lon": 6.8652, "elevation_m": 1035},
    {"lat": 45.8400, "lon": 6.8700, "elevation_m": 1210},
    {"lat": 45.8475, "lon": 6.8750, "elevation_m": 1390},
    {"lat": 45.8300, "lon": 6.8800, "elevation_m": 1180}
  ]
}

Summing the gain

Walk through the results in order and, for each consecutive pair, add the difference to your running total only when the elevation increased. In this example, 1035 to 1210 adds 175, 1210 to 1390 adds 180, and 1390 to 1180 adds nothing since that segment descends. Total elevation gain for this short stretch is 355 meters.

gain = 0
for i in 1..n:
  diff = elevation[i] - elevation[i-1]
  if diff > 0: gain += diff

Elevation loss, from the same data

The same loop, with the comparison flipped, gives you total descent instead, which matters just as much as gain for a route that finishes lower than it starts, such as a point-to-point ride down a mountain.

loss = 0
for i in 1..n:
  diff = elevation[i] - elevation[i-1]
  if diff < 0: loss += -diff

For the four points above, total loss is 210 meters, all of it from the final descending segment. A route summary that only reports gain and leaves out loss tells only half the story for anything that is not a simple out-and-back.

Point spacing changes the number

Elevation gain is sensitive to how many points you sample. Too few points smooths out real climbs and descents into an understated total. Too many points on a noisy GPS track can inflate the number with small up and down jitter that was never a real climb. A spacing of every ten to thirty meters along a hiking track, or resampled to even distance intervals, is a reasonable starting point.

A mistake worth avoiding

Running the gain calculation directly on a raw GPS track without resampling first is a common way to end up with an inflated number, since consumer GPS tracks often jitter up and down by a few meters between consecutive recorded points even on genuinely flat ground. Resample the track to even distance intervals before you request elevation for it, rather than requesting elevation for every raw point the device recorded.

Request cost

Each point is one request, whether sent through the points parameter or a bulk array. A route with 300 sampled points costs 300 requests, which is still a small share of the 2,500 free requests a day included with every key.

Elevation gain calculated this way is only as good as the point sampling behind it, so it is worth testing a couple of spacing choices against a known route before settling on one. Full request options are on the elevation lookup docs page.