Geofencing API
Check whether a coordinate lies inside a supplied boundary. The API accepts bounding boxes, GeoJSON polygons, and multipolygons. It uses Turf.js in memory. Each request includes the geometry to check, so no zone database, provider API, external service, or fallback is involved.
Authentication and setup
Both endpoints require x-app-id and x-api-key. Geofencing does not require x-provider-key. See Setup and authentication for credentials. For a local development credential, set NODE_ENV=development, configure the existing database, and run this from the repository root:
npm run app -- seed-dev
Copy the printed postman API key. It is shown once. To issue another key for the existing development app, run npm run app -- issue postman. Send the registered app slug as x-app-id and the complete <credential-id>.<secret> value as x-api-key.
All endpoints use POST, Content-Type: application/json, and a JSON body. They have no path or query parameters. Successful responses return the result object directly.
Coordinates and boundary formats
Point coordinates use { "lat": number, "lon": number } in decimal degrees. Latitude ranges from -90 to 90 and longitude from -180 to 180.
Use { "type": "bbox", "bbox": [west, south, east, north] } for a bounding box. The values are longitude/latitude and must be ordered west to east and south to north. Polygon and MultiPolygon geometries follow GeoJSON coordinate order [longitude, latitude]. Polygon rings must be closed, contain at least four positions, and be valid. Holes are supported. A point on the outer boundary counts as inside. A point within a hole counts as outside. For a fence crossing the antimeridian, split the area and supply a MultiPolygon.
POST /geofencing/check
Checks one point against one bounding box, Polygon, or MultiPolygon. Required headers are Content-Type: application/json, x-app-id, and x-api-key. The body requires point and geometry.
curl --request POST 'http://localhost:8000/geofencing/check' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"point": { "lat": 14.5995, "lon": 120.9842 },
"geometry": { "type": "bbox", "bbox": [120.95, 14.55, 121.02, 14.65] }
}'
HTTP 200 response body:
{"inside":true}
Polygon example body:
{
"point": { "lat": 14.6, "lon": 121.0 },
"geometry": {
"type": "Polygon",
"coordinates": [[[120.95, 14.55], [121.02, 14.55], [121.02, 14.65], [120.95, 14.65], [120.95, 14.55]]]
}
}
The result is {"inside":true} when the point lies within or on the boundary, and {"inside":false} otherwise.
POST /geofencing/match
Checks one point against up to 25 caller-supplied zones. The body requires point and a zones array. Each zone requires a unique id and a geometry in one of the supported formats. The response contains matching zone IDs in the same order as the submitted zones. No matches returns an empty matchedZoneIds array.
curl --request POST 'http://localhost:8000/geofencing/match' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"point": { "lat": 14.5995, "lon": 120.9842 },
"zones": [
{ "id": "manila", "geometry": { "type": "bbox", "bbox": [120.95, 14.55, 121.02, 14.65] } },
{ "id": "cebu", "geometry": { "type": "bbox", "bbox": [123.8, 10.2, 124.0, 10.4] } }
]
}'
HTTP 200 response body:
{"matchedZoneIds":["manila"]}
Errors and rate limits
Invalid coordinates, malformed or out-of-range bounding boxes, invalid polygon rings, duplicate zone IDs, more than 2,000 coordinate positions per geometry, or more than 25 zones return 400 Bad Request. Missing or invalid app credentials return 401 Unauthorized.
Both endpoints share 1,000 requests per rolling 60 seconds per authenticated application. A match request counts once regardless of its number of zones. The pre-authentication safety limit allows 1,200 requests per client IP per minute across routes. Exceeding a quota returns 429 Too Many Requests, code RATE_LIMIT_EXCEEDED, and Retry-After in seconds. Responses include X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Window, and X-RateLimit-Reset. See the rate-limiting guide.
Use cases
- Delivery areas: determine whether a customer address lies inside a store’s irregular delivery polygon.
- Service coverage: match a coordinate to one or more overlapping branch or service zones.
- Restricted areas: reject or flag coordinates within a caller-supplied exclusion polygon.
- Map-based workflows: check a location against a drawn boundary supplied by your application.
Geofencing answers whether points fall within supplied shapes. Use the Distance API to measure or rank coordinates and to check distance from a center using a radius.