Geospatial query
Searching your own database by location, such as 'nearest eligible drivers within 3 km', from stored coordinates rather than through a paid maps service.
Updated October 2026 · with examples from our own builds
What does geospatial query mean in practice?
Databases such as MongoDB can store points on a map and answer distance questions directly: who is nearest, who is inside this radius, sorted by distance. That powers matching, search by distance and coverage maps without calling a maps provider each time.
This is often the cheapest part of a location product, and the easiest to overlook. Matching on your own database costs nothing per query, whereas doing it through a paid distance API is billed on every request.
It needs coordinates stored in a geo format with the right index, and a decision about what 'near' means: straight-line distance, the provider's home, or the nearest place they actually work.
Geospatial query at a glance
- Answers
- Nearest, within a radius, sorted by distance
- Needs
- Coordinates in a geo format plus a geo index
- Cost per query
- Nothing beyond your own database
Where has geospatial query come up in our builds?
The nearest eligible drivers are found with a MongoDB $geoNear query in widening rings of 3, 7 and 15 km by default, so driver matching costs nothing in maps fees.
Candidates for a rescue case come from one $geoNear query with every eligibility filter inside the pipeline, so the nearest eligible responders come back first.
Clients search within 5, 10, 25 or 50 km, measured from a trainer's own location or the nearest place they train. Because coordinates are stored as separate fields, the server computes haversine distance across the whole list before paging, so page one really holds the nearest trainers.
Common questions about geospatial query
Do I need Google Maps to find the nearest provider?
No. A geospatial query on your own database answers 'who is nearest' at no per-query cost. A maps service is still needed for road routes, address search and drawing the map.
Why does sorting by distance break when results are paged?
If the server pages the list first and measures distance afterwards, page one holds whoever happened to be first in the list, not the nearest. Distance has to be computed, or queried, before paging.
Related terms
Sources
Planning a product and not sure where geospatial query fits? Ask us, or browse all 116 terms in the glossary.