How to Find Places in a Custom Polygon
- API or service
- Places API
- Task
- GeoJSON boundary → places inside the area
- Examples
- Difficulty
- Intermediate
- Time
- 10 min
You have a boundary drawn by a user, exported from GIS software, or defined by your application and need matching places inside it. Send the boundary as inline GeoJSON in a Places API POST request with a polygon filter. Use a polyline filter with a buffer when you need a corridor around a line instead.
Task flow: Polygon or MultiPolygon → Places API POST → matching places inside the area.
This guide shows separate requests for restaurants inside an Atlanta polygon and near an Atlanta polyline.
Find places in a polygon
Use a GeoJSON Polygon or MultiPolygon when the enclosed area defines where places should be located.
POST https://api.geoapify.com/v2/places?apiKey=YOUR_API_KEY
Content-Type: application/json
{
"categories": ["catering.restaurant"],
"filter": {
"type": "polygon",
"geometry": {
"type": "Polygon",
"coordinates": [[
[-84.38456, 33.78971],
[-84.37394, 33.78971],
[-84.37394, 33.79783],
[-84.38456, 33.79783],
[-84.38456, 33.78971]
]]
},
"buffer": 0
},
"limit": 100,
"offset": 0
}
This request finds restaurants inside a small boundary near Piedmont Park in Atlanta. A polygon buffer may be from 0 through 100,000 metres. Set it to 0, or omit it, to search only inside the polygon.
Every position uses [longitude, latitude] order. Close each ring by repeating its first position at the end, and include at least three distinct positions. The first ring is the exterior; later rings are holes. A MultiPolygon contains separate polygons with the same ring structure.
The API accepts at most 10,000 source positions, 100 polygon rings, and 102,400 UTF-8 bytes for the geometry value. It validates ring closure and distinct positions, but does not check self-intersections or whether holes lie inside an outer ring. Validate user-drawn or imported geometry before sending it.
Find places near a polyline with a buffer
Use a GeoJSON LineString or MultiLineString when places should be close to a path rather than inside an enclosed area.
POST https://api.geoapify.com/v2/places?apiKey=YOUR_API_KEY
Content-Type: application/json
{
"categories": ["catering.restaurant"],
"filter": {
"type": "polyline",
"geometry": {
"type": "LineString",
"coordinates": [
[-84.38456, 33.78971],
[-84.37925, 33.79377],
[-84.37394, 33.79783]
]
},
"buffer": 100
},
"limit": 100,
"offset": 0
}
This request finds restaurants within 100 metres of the Atlanta line. Positions use [longitude, latitude] order. The buffer must be greater than 0 and no more than 100,000 metres; omitting it uses the default of 1,000 metres.
The API accepts at most 10,000 source positions and 102,400 UTF-8 bytes for the geometry value. It does not simplify the line or snap it to roads. The buffer measures geographic proximity, not travel distance or time.
Use a polygon filter when the enclosed area matters. A buffered polyline searches only around the line and does not include the whole polygon interior.