DEV Community

Cover image for 30 Isochrones, 3 Requests: Draw a Drive-Time Map in 1-Minute Bands
Casey Rivers for Geoapify Maps API

Posted on

30 Isochrones, 3 Requests: Draw a Drive-Time Map in 1-Minute Bands

An isochrone answers one question: where can I get in 15 minutes? Stack 30 of them, one per minute, and the map turns into a drive-time surface: you see the highways stretch the city into long fingers and the mountains stop it cold.

In this tutorial we draw that map for Denver with the Geoapify Isoline API and MapLibre: 30 one-minute bands from green to dark red, under the roads, with the minutes on hover. It takes three requests, not one, and we'll see why. At the end, we ask an AI coding assistant to build the same page.

TL;DR

  • The Isoline API returns one polygon per range: type=time, range in seconds, several values separated by commas.
  • One request takes up to 10 ranges. Thirty one-minute bands need three requests: 1–10, 11–20 and 21–30 minutes, sent in parallel.
  • A request is billed by its largest range (every 5 minutes cost 1 credit): 2 + 4 + 6 = 12 credits for the whole map. The Free plan has 3,000 credits a day.
  • Draw the bands from the largest to the smallest and insert the layer under the roads, so the streets stay readable.
  • An AI assistant asked for all 30 ranges in one request from a vague prompt and got a 400, so its map stayed empty. A precise prompt got our demo.

👉 Live demo: click the map to move the starting point, hover it to see the minutes.


Table of Contents

  1. Why 1-minute bands?
  2. Why three requests?
  3. What the bands show in three cities
  4. Step 1: Request 30 one-minute isochrones
  5. Step 2: Wait for long calculations
  6. Step 3: Draw the bands under the roads
  7. Let an AI assistant write it
  8. Summary
  9. FAQ

Why 1-minute bands?

The classic isochrone map has a few rings: 5, 10, 15 minutes. That's enough to answer "is it within 15 minutes?", but each band hides a lot: everything inside one ring looks the same.

Two maps of the Denver area from Union Station side by side. Left: 6 bands in 5-minute steps from one request, flat blocks of color. Right: 30 bands in 1-minute steps from three requests, a smooth gradient from green downtown to dark red at 30 minutes, with the highways visible as long fingers

With 30 bands, the gradient shows how the city is reachable: I-25 and I-70 pull the colors outward, the green core is stretched along the fast roads, and areas without public roads stay white.

Why three requests?

range takes a list, and each value comes back as its own polygon. The limit is 10 values per request; with 11 or more, the API answers 400 with the message "range" must contain less than or equal to 10 items.

So the 30 minutes go out as three requests, in parallel:

Request range (seconds) Response Time Credits
1–10 min 60,120,…,600 0.5 MB ~3 s 2
11–20 min 660,720,…,1200 1.1 MB ~6 s 4
21–30 min 1260,1320,…,1800 3.2 MB ~27 s 6

Measured from Denver Union Station with mode=drive. The outer bands are bigger polygons with more detail, so the last request takes longest. Credits count only the largest range of each request, so the 30 bands cost 12 credits, while a single 30-minute isochrone costs 6.

What the bands show in three cities

The same 30 bands, at the same scale, from three city centers:

Three drive-time maps at the same scale, each with 30 one-minute bands from green to dark red. Denver from Union Station spreads in all directions with long fingers along the interstates. Salt Lake City from Temple Square is squeezed into a north-south strip along I-15 between the lake and the mountains. Pittsburgh from Market Square is a ragged, almost round shape

  • Denver spreads wide on a flat grid, with fingers along the interstates.
  • Salt Lake City can only grow north and south: the 30 minutes run along I-15 between the Great Salt Lake and the mountains.
  • Pittsburgh, with its rivers and hills, grows in all directions but slowly, into a ragged, almost round shape.

Step 1: Request 30 one-minute isochrones

type=time takes seconds. Build three groups of 10 ranges and send them at once.

const groups = [[1, 10], [11, 20], [21, 30]]; // minutes

const collections = await Promise.all(groups.map(([from, to]) => {
  const ranges = [];
  for (let minute = from; minute <= to; minute++) ranges.push(minute * 60); // seconds

  return fetchIsoline(
    `https://api.geoapify.com/v1/isoline?lat=39.7527&lon=-105.0003` +
    `&type=time&mode=drive&range=${ranges.join(",")}&apiKey=YOUR_API_KEY`
  );
}));
Enter fullscreen mode Exit fullscreen mode
Parameter Value Meaning
lat, lon 39.7527, -105.0003 The starting point (Denver Union Station)
type time Isochrones; distance gives isodistances in meters
mode drive Also walk, bicycle, truck and more
range 60,120,…,600 Up to 10 values, in seconds, up to 3,600 (60 minutes)

Each response is a GeoJSON FeatureCollection with one feature per range; properties.range holds its value in seconds. An isoline shows how far you get from the point. Driving towards it can take a little longer or shorter because of one-way streets and ramps.

Step 2: Wait for long calculations

Big isolines can take longer than the API waits. Then it answers 202 with an empty FeatureCollection and an id, and you fetch the result by that id a bit later.

async function fetchIsoline(url) {
  let response = await fetch(url);

  while (response.status === 202) {
    const pending = await response.json();
    await new Promise((resolve) => setTimeout(resolve, 2000));
    response = await fetch(
      `https://api.geoapify.com/v1/isoline?id=${pending.properties.id}&apiKey=YOUR_API_KEY`
    );
  }
  return response.json();
}
Enter fullscreen mode Exit fullscreen mode

Fetching an isoline by id costs 1 credit per request, so wait a couple of seconds between tries. In our tests, all three Denver requests answered 200 directly.

Step 3: Draw the bands under the roads

The bands overlap: the 30-minute polygon contains the 29-minute one, and so on. Sort them from the largest to the smallest, so each smaller band is drawn on top, and store a color in each feature.

// Color stops in minutes: green → yellow → dark red at 30
const STOPS = [[0, [26, 152, 80]], [10, [145, 207, 96]], [15, [254, 224, 139]],
               [20, [252, 141, 89]], [25, [215, 48, 39]], [30, [127, 0, 0]]];

const features = collections
  .flatMap((collection) => collection.features)
  .sort((a, b) => b.properties.range - a.properties.range) // largest first
  .map((feature) => {
    const minutes = feature.properties.range / 60;
    return { ...feature, properties: { minutes, color: colorForMinutes(minutes) } };
  });

map.getSource("isolines").setData({ type: "FeatureCollection", features });
Enter fullscreen mode Exit fullscreen mode

colorForMinutes blends between the two stops around the value. Then add one fill layer before the first road layer of the map style, so roads and labels stay on top of the colors:

const firstRoadLayer = map.getStyle().layers
  .find((layer) => layer["source-layer"] === "transportation");

map.addLayer({
  id: "isoline-bands",
  type: "fill",
  source: "isolines",
  paint: { "fill-color": ["get", "color"], "fill-opacity": 0.8 },
}, firstRoadLayer.id);
Enter fullscreen mode Exit fullscreen mode

For the hover popup, take the smallest band under the cursor: that's the drive time to that spot.

map.on("mousemove", "isoline-bands", (event) => {
  const minutes = Math.min(...event.features.map((f) => f.properties.minutes));
  popup.setLngLat(event.lngLat).setHTML(`Within <strong>${minutes} min</strong> by car`).addTo(map);
});
Enter fullscreen mode Exit fullscreen mode

Let an AI assistant write it

We gave the task to an AI coding assistant (Claude) twice, each time in a fresh session without web access, and ran both pages with a real API key.

Prompt 1, vague:

Using the Geoapify API, make a web page with a drive-time map of Denver in 1-minute steps, up to 30 minutes from Union Station. One HTML file please.

Page written by an AI assistant from the vague prompt: a Leaflet map of the Denver area with only a marker at Union Station and no colored bands; the legend box in the corner reads "Failed to load isolines: HTTP 400"

The page looked right in the code: the correct endpoint, type=time, ranges in seconds, sorting from the largest band to the smallest, a green-to-red legend, 70 lines with Leaflet. But it put all 30 ranges in one request, and the API answered 400. The map stays empty, with "Failed to load isolines: HTTP 400" in the corner.

Prompt 2, precise: we named the library and version, the endpoint, the 10-range limit and the three groups, the 202 handling, the sort order, the color stops, the layer position under the roads and the hover popup.

Page written by an AI assistant from the precise prompt: a MapLibre map of the Denver area with 30 one-minute drive-time bands from green at Union Station to dark red at 30 minutes, drawn under the roads, and a side panel with a gradient legend and "Done: 30 bands"

The same map as our demo, in 146 lines: three parallel requests and all 30 bands under the roads. The code also has the hover popup and click-to-move (we checked the first load).

What made the difference:

  • The limit. The assistant can't know that a request takes at most 10 ranges. Say it, and say how to split.
  • Layer order. "Under the roads" needs the beforeId of the first road layer; without it, the bands cover the streets.
  • Sort order. Largest first, or the big bands paint over the small ones.
  • Name the versions. Otherwise you get the libraries the assistant remembers.

Summary

  • GET /v1/isoline?type=time&mode=drive&range=60,120,… returns one polygon per range, in seconds.
  • One request takes up to 10 ranges; 30 one-minute bands need three requests, 60 bands need six.
  • Credits count only the largest range of each request (every 5 minutes = 1 credit): 12 credits for 30 one-minute bands.
  • Handle 202 by fetching the result by its id.
  • Draw from the largest to the smallest band, in one fill layer inserted under the first road layer.

FAQ

How do I get isochrones for several times in one request?
Pass them all in range, separated by commas, in seconds: range=300,600,900. The response has one feature per range.

How many ranges can one request take?
Up to 10. With more, the API answers 400. Split them into several requests and send them in parallel.

What does a multi-range isoline cost?
Only the largest range counts: every 5 minutes cost 1 credit, so range=300,600,900 costs 3 credits. Our three requests (up to 10, 20 and 30 minutes) cost 2 + 4 + 6 = 12 credits.

What's the maximum time?
60 minutes (range=3600) for an isochrone and 60 km for an isodistance. A full hour in one-minute bands means six requests and 42 credits; our 51–60-minute request for Denver returned 4.8 MB in 16 seconds.

Why does the API answer 202?
The calculation took longer than the API waits. The body holds properties.id; fetch /v1/isoline?id=… a little later. Each fetch by id costs 1 credit.

Does an isochrone show who can reach a place?
Not exactly. It shows how far you can get from the point. In a city the two directions are close, but one-way streets and highway ramps make them differ. For exact times from many places to one place, use the Route Matrix API (tutorial).

Can I store the polygons?
Yes. Geoapify allows caching and storing calculated isolines, so you can draw the same map again without new requests.


Try it

More drive-time tutorials:

Get a free API key at myprojects.geoapify.com and draw the bands around your own city. Which highway stretches your 30 minutes the furthest? Tell us in the comments.

Top comments (0)