How to Check Which Locations Lie Above a Given Elevation

API or service
Elevation API
Task
Locations → elevation → above or below a threshold
Examples
URLJavaScriptMapLibre GLAI
Difficulty
Beginner
Time
8 min

Check which of your locations lie above a given elevation

You have a list of locations (hotels, trip stops, stores, sensor sites) and need to know which of them lie above a certain elevation: to warn travelers about altitude, apply high-altitude cooking or equipment rules, or simply sort places by height. The Elevation API returns the terrain height of up to 1,000 locations in one request, so the whole check is one call and a filter.

The example checks 12 Colorado towns against 8,000 ft. The CDC Yellow Book uses that line for altitude illness: "Any unacclimatized traveler proceeding to a sleeping altitude of ≥2,450 m (≥8,000 ft)—and sometimes lower—is at risk for altitude illness." Use whichever threshold your rule needs.

Task flow: locations → one Elevation API request → elevation per location → above or below the threshold → list or map.

Get the elevation of all locations in one request

Send the coordinates as [longitude, latitude] arrays. units=imperial returns feet; leave it out for meters:

POST https://api.geoapify.com/v1/geodata/elevation?apiKey=YOUR_API_KEY
Content-Type: application/json
{
  "units": "imperial",
  "locations": [
    [-104.9849, 39.7392],
    [-104.8253, 38.834],
    [-105.5232, 40.3772],
    [-105.7856, 39.918],
    [-106.0465, 39.4829],
    [-106.3888, 39.6438],
    [-106.2925, 39.2508],
    [-106.8236, 39.1911],
    [-106.984, 38.8698],
    [-107.8123, 37.9375],
    [-106.8317, 40.4848],
    [-107.8766, 37.2769]
  ]
}

Reduced response (the first two of 12 results):

{
  "results": [
    { "location": { "lon": -104.9849, "lat": 39.7392 }, "elevation": 5279, "units": "ft" },
    { "location": { "lon": -104.8253, "lat": 38.834 }, "elevation": 6007, "units": "ft" }
  ]
}

Results come back in the order of locations. The response has no names or ids, so keep your own list in the same order and join by index. All 12 results, from a live request on November 17, 2026:

Town (city center from the Geocoding API) Elevation, ft Elevation, m
Denver 5,279 1,609
Colorado Springs 6,007 1,831
Estes Park 7,615 2,321
Winter Park 8,802 2,683
Breckenridge 9,567 2,916
Vail 8,150 2,484
Leadville 10,157 3,096
Aspen 7,907 2,410
Crested Butte 8,904 2,714
Telluride 8,793 2,680
Steamboat Springs 6,729 2,051
Durango 6,562 2,000

The request costs 1 credit: max(1, ceil(locations / 100)), so 100 locations cost 1 credit and 1,000 cost 10. More than 1,000 locations need several requests.

Flag the locations above the threshold

Join the results with your locations and compare each elevation with the threshold. Use the same unit for both:

const towns = [
  { name: "Denver", location: [-104.9849, 39.7392] },
  { name: "Leadville", location: [-106.2925, 39.2508] },
  { name: "Aspen", location: [-106.8236, 39.1911] }
  // ...
];
const THRESHOLD_FT = 8000;

const response = await fetch(
  "https://api.geoapify.com/v1/geodata/elevation?apiKey=YOUR_API_KEY",
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      units: "imperial",
      locations: towns.map(town => town.location)
    })
  }
);
if (!response.ok) {
  throw new Error((await response.json()).message);
}
const { results } = await response.json();

const checked = towns.map((town, i) => ({
  ...town,
  elevation: results[i].elevation,
  above: results[i].elevation !== null && results[i].elevation >= THRESHOLD_FT
}));

const above = checked.filter(town => town.above)
  .sort((a, b) => b.elevation - a.elevation);

For the 12 towns, 6 are at or above 8,000 ft: Leadville (10,157 ft), Breckenridge (9,567), Crested Butte (8,904), Winter Park (8,802), Telluride (8,793), and Vail (8,150). Aspen (7,907 ft) and Estes Park (7,615 ft) are close, but below.

A few things to keep in mind:

  • The elevation is for the point you send. A town or a resort covers a range of heights. For a hotel, send the hotel's coordinates, not the town center; geocode the address first if you only have an address.
  • elevation can be null where no data is available. Treat those locations as unknown, not as "below".
  • Values are whole feet or meters. Near the threshold, a point a few meters away can fall on the other side; show the elevation next to the flag so users can judge.

Show the result on a map

Add "format": "geojson" to the request to get a FeatureCollection of points with elevation and units in properties, ready for a map layer:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": { "elevation": 10157, "units": "ft" },
      "geometry": { "type": "Point", "coordinates": [-106.2925, 39.2508] }
    }
  ]
}

With MapLibre GL, color each point by the threshold with a case expression:

map.addSource("locations", { type: "geojson", data: elevationGeoJSON });

map.addLayer({
  id: "locations",
  type: "circle",
  source: "locations",
  paint: {
    "circle-radius": 7,
    "circle-stroke-width": 2,
    "circle-stroke-color": "#ffffff",
    "circle-color": [
      "case",
      [">=", ["get", "elevation"], 8000], "#d1495b",
      "#2e86ab"
    ]
  }
});

The comparison expects a number, so remove features with a null elevation before adding the source, or put them on a separate layer if you want to show them as unknown. As in the JSON format, features follow the order of locations and carry no names: add your own properties (for example name) by index before adding the source.

Elevation threshold check with an AI coding agent

Copy this prompt into Codex, Claude Code, Cursor, or another coding agent to flag locations above a chosen elevation in your project.

Add an elevation threshold check to my project with the Geoapify Elevation API.

Before you start
- Inspect the existing project first. Reuse its current framework, HTTP client, data model for locations, map library, and conventions. Make the smallest necessary changes.
- Ask only what the project does not answer: which locations to check, the threshold and its unit (feet or meters), and whether requests run in a backend or use a restricted browser API key.
- Read the Geoapify API key from the project's environment configuration. Never hardcode, print, or log it.

API request
- POST https://api.geoapify.com/v1/geodata/elevation?apiKey=... with JSON { "units": "imperial" | "metric", "locations": [[lon, lat], ...] }. Add "format": "geojson" if the result goes to a map layer.
- Up to 1,000 locations per request; split larger lists into chunks. Cost per request: max(1, ceil(locations / 100)) credits.
- Results (or GeoJSON features) keep the input order and contain no ids: join them with the input locations by index.

Threshold
- above = elevation !== null && elevation >= threshold, in the same unit as the request.
- Treat null elevations as unknown, not as below the threshold. Show the elevation value next to the flag.
- Use the exact coordinates of each place (geocode addresses first), not a city center.

Errors
- Show the API message for HTTP 400 responses, and retry 429 responses a limited number of times with backoff.
- Add a test with a mocked response that includes a null elevation and a value equal to the threshold.

Review the generated code against this guide. Check the coordinate order ([longitude, latitude]), the unit of the threshold, the index join, and the API-key handling.