How to Check Whether a Location Is Inside a Service Area

API or service
Isoline API + Geometry Operations API
Task
Service area + candidate location → inside or outside
Examples
URLJavaScript
Difficulty
Intermediate
Time
10 min

Check whether a location is inside a service area

You have a service-area polygon and a candidate address, customer, vehicle, or facility coordinate. Use the Geometry Operations API to return a boolean indicating whether that point is contained by the area.

Task flow: origin + time limit → Isoline API polygon; polygon + candidate point → Geometry Operations API → true or false.

The candidate must already be coordinates. If it starts as an address, geocode it first, then use the returned longitude and latitude to construct the GeoJSON point.

Create the service-area geometry

Request the service area whose rule you need to test. This example calculates a 15-minute drive-time area around central Berlin:

https://api.geoapify.com/v1/isoline?lat=52.52&lon=13.405&type=time&mode=drive&range=900&traffic=free_flow&format=geojson&apiKey=YOUR_API_KEY

Keep features[0].geometry from the complete response. The geometry can be a Polygon or MultiPolygon, and the Geometry Operations API accepts either.

Use the same stored service-area geometry for many candidate checks when the origin, range, mode, and routing preferences have not changed. Recalculate it when any of those business rules changes.

Test candidate locations with JavaScript

The contains operation expects geometry1 to be the containing polygon and geometry2 to be the candidate geometry. GeoJSON point coordinates use [longitude, latitude] order.

const apiKey = "YOUR_API_KEY";

async function isInsideServiceArea(serviceAreaGeometry, longitude, latitude) {
  const response = await fetch(
    `https://api.geoapify.com/v1/geometry/operation?apiKey=${encodeURIComponent(apiKey)}`,
    {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        operation: "contains",
        geometry1: serviceAreaGeometry,
        geometry2: {
          type: "Point",
          coordinates: [longitude, latitude]
        }
      })
    }
  );

  if (!response.ok) throw new Error(`Containment check failed: ${response.status}`);
  const result = await response.json();
  return result.data;
}

const serviceAreaGeometry = isolineResponse.features[0].geometry;

console.log(await isInsideServiceArea(serviceAreaGeometry, 13.405, 52.52));
// true: the calculation origin is inside this 15-minute area

console.log(await isInsideServiceArea(serviceAreaGeometry, 13.75, 52.52));
// false: this candidate is outside the area

The validated responses for these two checks are:

{ "type": "boolean", "data": true }
{ "type": "boolean", "data": false }

Treat an API error separately from data: false; only the latter is a valid outside result. Decide explicitly how the application handles points exactly on a business boundary, coordinate uncertainty, and stale service-area calculations.