_geoPoint sort rule orders results by their distance from a specified latitude and longitude. Use this to show users the nearest matching results first, or to push nearby results to the end of the list.
Syntax
| Parameter | Type | Description |
|---|---|---|
lat | Float | Latitude of the reference point |
lng | Float | Longitude of the reference point |
:asc to show the closest results first, or :desc to show the farthest results first.
Sort by proximity
The following example sorts restaurants by their distance from the Eiffel Tower (latitude 48.8561446, longitude 2.2978204), with the closest results first:Understanding _geoDistance
When you use _geoPoint for sorting, Meilisearch automatically includes a _geoDistance field in each result. This value represents the distance in meters between the document’s location and the reference point you specified.
_geoDistance is a computed field that only appears in search results. It is not stored in your documents and cannot be used as a filter or sort rule.Combine with other sort rules
_geoPoint works alongside other sort rules. You can sort by proximity first, then break ties with another attribute. The following example sorts restaurants by distance from the Eiffel Tower, then by rating in descending order:
Combine with geo filters
You can use_geoPoint sorting together with geo filters to both limit results to a geographic area and order them by proximity. For example, find restaurants within 5 km of central Milan, sorted by distance:
Geo search overview
Learn about all geo search capabilities in Meilisearch.
Search API reference
Full reference for the search endpoint and sort parameter.