How to Draw a Radius Circle on a Map and Compare It With a Drive-Distance Area

API or service
Isoline API + MapLibre GL
Task
Center and distance → radius circle and drive-distance area on a map
Examples
URLJSMapLibre GL
Difficulty
Beginner
Time
10 min

Draw a radius circle and a drive-distance area

You have a location and a distance, such as 5 miles, and need to show what lies within that distance. A radius circle answers the question in a straight line. A drive-distance area, calculated by the Geoapify Isoline API as an isodistance, answers it along the road network.

This guide draws both for the same center and the same distance: downtown Memphis, Tennessee, and 8,047 meters (5 miles). The two layers on one map show where the straight-line answer and the road answer differ.

Task flow: center + distance → circle polygon and Isoline API isodistance → two GeoJSON layers on a map.

In this example, the circle covers 203.4 km². The drive-distance area covers 71.1 km², about 35% of the circle, because the Mississippi River can be crossed only on bridges and streets do not run in straight lines from the center.

Request the drive-distance area for the same distance

Set type=distance, mode=drive, and range=8047. Distance ranges are always expressed in meters, so 5 miles is 5 × 1609.344 ≈ 8047 meters.

https://api.geoapify.com/v1/isoline?lat=35.1495&lon=-90.049&type=distance&mode=drive&range=8047&apiKey=YOUR_API_KEY
Parameter Value Meaning
lat, lon 35.1495, -90.049 The center, the same as the circle center.
type distance Calculate an isodistance rather than an isochrone.
mode drive Measure the distance on roads open to passenger cars.
range 8047 Include locations reachable within 8,047 meters of driving.

Use another travel mode, such as walk or bicycle, to measure the distance on the network for that mode. The available range depends on your pricing plan; the Free plan calculates isodistances up to 10 km, which covers this example.

Reduced response: The polygon coordinates are omitted because the complete MultiPolygon is large.

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "lat": 35.1495,
        "lon": -90.049,
        "mode": "drive",
        "type": "distance",
        "range": 8047,
        "id": "929714c3bdda62cc9bacea742c5e5413"
      },
      "geometry": {
        "type": "MultiPolygon"
      }
    }
  ]
}

Use the complete geometry returned by the API for display or later spatial operations. Do not copy the reduced response into an application.

Create the radius circle as a GeoJSON polygon

A radius circle needs no API request: it is the set of points at the same straight-line distance from the center. MapLibre GL has no layer that takes a radius in meters (its circle layer type draws points with a radius in pixels), so create the circle as a GeoJSON polygon.

This function calculates 64 points around the center with the great-circle destination formula and closes the ring:

function circlePolygon(lon, lat, radiusMeters, steps = 64) {
  const earthRadius = 6371008.8;
  const toRad = degrees => (degrees * Math.PI) / 180;
  const toDeg = radians => (radians * 180) / Math.PI;
  const angularDistance = radiusMeters / earthRadius;
  const lat1 = toRad(lat);
  const lon1 = toRad(lon);
  const ring = [];
  for (let i = 0; i <= steps; i++) {
    const bearing = (2 * Math.PI * i) / steps;
    const lat2 = Math.asin(
      Math.sin(lat1) * Math.cos(angularDistance) +
        Math.cos(lat1) * Math.sin(angularDistance) * Math.cos(bearing)
    );
    const lon2 =
      lon1 +
      Math.atan2(
        Math.sin(bearing) * Math.sin(angularDistance) * Math.cos(lat1),
        Math.cos(angularDistance) - Math.sin(lat1) * Math.sin(lat2)
      );
    ring.push([toDeg(lon2), toDeg(lat2)]);
  }
  return { type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [ring] } };
}

const center = { lat: 35.1495, lon: -90.049 };
const distance = 8047; // meters, about 5 miles

const radiusCircle = circlePolygon(center.lon, center.lat, distance);

The function takes lon, lat and returns positions in [longitude, latitude] order, as GeoJSON requires. Calculating the points on the sphere keeps the circle correct at any latitude; adding the same number of degrees in every direction would stretch it.

A 5-mile radius circle around downtown Memphis, Tennessee, drawn as a dashed orange GeoJSON polygon with MapLibre GL on a Geoapify map; it covers the Mississippi River and part of Arkansas

The screenshot shows the circle on its own, with the fill and dashed outline used in the next step.

In Leaflet, the built-in circle already takes a radius in meters, so the function is not needed:

L.circle([35.1495, -90.049], { radius: 8047 }).addTo(map);

Display both areas with MapLibre GL

Use this after creating a MapLibre map and waiting for its load event. It requests the drive-distance area, adds it above the radiusCircle polygon from the previous step, and fits the map to the circle.

const apiKey = "YOUR_API_KEY";
const params = new URLSearchParams({
  lat: center.lat,
  lon: center.lon,
  type: "distance",
  mode: "drive",
  range: distance,
  apiKey
});

const response = await fetch(`https://api.geoapify.com/v1/isoline?${params}`);
if (!response.ok) throw new Error(`Isoline request failed: ${response.status}`);

const driveDistanceArea = await response.json();
if (!driveDistanceArea.features?.length) throw new Error("No drive-distance area was returned");

// The circle goes below the drive-distance area.
map.addSource("radius-circle", { type: "geojson", data: radiusCircle });
map.addLayer({
  id: "radius-circle-fill",
  type: "fill",
  source: "radius-circle",
  paint: { "fill-color": "#f76707", "fill-opacity": 0.1 }
});
map.addLayer({
  id: "radius-circle-outline",
  type: "line",
  source: "radius-circle",
  paint: { "line-color": "#f76707", "line-width": 2, "line-dasharray": [3, 2] }
});

map.addSource("drive-distance", { type: "geojson", data: driveDistanceArea });
map.addLayer({
  id: "drive-distance-fill",
  type: "fill",
  source: "drive-distance",
  paint: { "fill-color": "#623aff", "fill-opacity": 0.3 }
});
map.addLayer({
  id: "drive-distance-outline",
  type: "line",
  source: "drive-distance",
  paint: { "line-color": "#623aff", "line-width": 2 }
});

new maplibregl.Marker({ color: "#222222" }).setLngLat([center.lon, center.lat]).addTo(map);

// The drive-distance area lies inside the circle, so fit the map to the circle.
const bounds = new maplibregl.LngLatBounds();
radiusCircle.geometry.coordinates[0].forEach(position => bounds.extend(position));
map.fitBounds(bounds, { padding: 40 });

Downtown Memphis on a Geoapify map: the dashed orange 5-mile radius circle and, inside it, the purple Isoline API drive-distance area for 8,047 meters, which crosses the Mississippi River only as narrow strips along the bridges

The screenshot was rendered from this code with MapLibre GL JS 4.7.1 and the Geoapify osm-bright map style.

The drive-distance area always lies inside the circle, because a route on roads is never shorter than the straight line. The space between the two outlines is everything that is within the distance on the map but farther by road.

In the Memphis example, the gap is largest west of the center. The circle covers the Mississippi River and the Arkansas side. The drive-distance area crosses the river only as narrow strips along the two bridges, because it follows the roads. A point on Presidents Island, 7.8 km from the center in a straight line, is 11.0 km away by road and falls outside the 5-mile drive-distance area.

Use the circle for straight-line questions, such as a signal range or a legal buffer. Use the drive-distance area when the distance on roads matters, such as a delivery fee by distance. When the question is about time, request an isochrone instead: see Create a drive-time service area.