How to Find the Nearest Place by Category
- API or service
- Places API
- Task
- Category + location → nearest matching place
- Examples
- Difficulty
- Beginner
- Time
- 5 min
You have a location and a type of place—such as a pharmacy, supermarket, restaurant, fuel station, or EV charging station—and need the closest matching result. The Geoapify Places API searches hierarchical place categories and can order matching places by distance from a longitude and latitude.
Use a proximity bias when “nearest” is the main requirement. Add a circle filter when results must also stay within a maximum search radius.
Request the nearest place
Choose a key from the Places category list, set bias=proximity:longitude,latitude, and use limit=1 to return only the nearest match. This request finds the nearest discount store to a point in Memphis:
https://api.geoapify.com/v2/places?categories=commercial.discount_store&bias=proximity:-89.9324387,35.1438339&limit=1&apiKey=YOUR_API_KEY
The proximity bias changes the result order but does not impose a maximum distance. If a distant result is not useful, add filter=circle:longitude,latitude,radiusMeters. The following request returns the nearest matching place only when it is within 1,000 metres of the origin:
https://api.geoapify.com/v2/places?categories=commercial.discount_store&filter=circle:-89.9324387,35.1438339,1000&bias=proximity:-89.9324387,35.1438339&limit=1&apiKey=YOUR_API_KEY
Reduced response: The response below keeps the nearest place's identity, address, category, distance, and coordinates.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Dollar General",
"housenumber": "4111",
"street": "Summer Avenue",
"city": "Memphis",
"state": "Tennessee",
"postcode": "38122",
"country": "United States",
"country_code": "us",
"formatted": "Dollar General, 4111 Summer Avenue, Memphis, TN 38122, United States of America",
"categories": [
"commercial",
"commercial.discount_store"
],
"distance": 943,
"lat": 35.1484713,
"lon": -89.9237661,
"place_id": "51d229d9fb1e7b56c05982f2881b01934140f00103f9014cb1b8260100000092030e446f6c6c61722047656e6572616c"
},
"geometry": {
"type": "Point",
"coordinates": [-89.9237661, 35.1484713]
}
}
]
}
Coordinates in proximity and circle are ordered as longitude, latitude. Read the place coordinates from geometry.coordinates or the lat and lon properties. When proximity bias is present, properties.distance gives the distance from the origin in metres. Keep properties.place_id when the application may request additional Place Details later.