Skip to main content
The _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

_geoPoint(lat, lng):asc
_geoPoint(lat, lng):desc
ParameterTypeDescription
latFloatLatitude of the reference point
lngFloatLongitude of the reference point
Use :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:
curl \
  -X POST 'MEILISEARCH_URL/indexes/restaurants/search' \
  -H 'Content-type:application/json' \
  --data-binary '{ "sort": ["_geoPoint(48.8561446,2.2978204):asc"] }'
{
  "hits": [
    {
      "id": 2,
      "name": "Bouillon Pigalle",
      "address": "22 Bd de Clichy, 75018 Paris, France",
      "type": "french",
      "rating": 8,
      "_geo": {
        "lat": 48.8826517,
        "lng": 2.3352748
      },
      "_geoDistance": 4156
    },
    {
      "id": 3,
      "name": "Artico Gelateria Tradizionale",
      "address": "Via Dogana, 1, 20123 Milan, Italy",
      "type": "ice cream",
      "rating": 10,
      "_geo": {
        "lat": 45.4632046,
        "lng": 9.1719421
      },
      "_geoDistance": 640728
    },
    {
      "id": 1,
      "name": "Nàpiz' Milano",
      "address": "Viale Vittorio Veneto, 30, 20124, Milan, Italy",
      "type": "pizza",
      "rating": 9,
      "_geo": {
        "lat": 45.4777599,
        "lng": 9.1967508
      },
      "_geoDistance": 640207
    }
  ]
}

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:
curl \
  -X POST 'MEILISEARCH_URL/indexes/restaurants/search' \
  -H 'Content-type:application/json' \
  --data-binary '{
    "sort": [
      "_geoPoint(48.8561446,2.2978204):asc",
      "rating:desc"
    ]
  }'
{
  "hits": [
    {
      "id": 2,
      "name": "Bouillon Pigalle",
      "address": "22 Bd de Clichy, 75018 Paris, France",
      "type": "french",
      "rating": 8,
      "_geo": {
        "lat": 48.8826517,
        "lng": 2.3352748
      },
      "_geoDistance": 4156
    },
    {
      "id": 3,
      "name": "Artico Gelateria Tradizionale",
      "address": "Via Dogana, 1, 20123 Milan, Italy",
      "type": "ice cream",
      "rating": 10,
      "_geo": {
        "lat": 45.4632046,
        "lng": 9.1719421
      },
      "_geoDistance": 640728
    },
    {
      "id": 1,
      "name": "Nàpiz' Milano",
      "address": "Viale Vittorio Veneto, 30, 20124, Milan, Italy",
      "type": "pizza",
      "rating": 9,
      "_geo": {
        "lat": 45.4777599,
        "lng": 9.1967508
      },
      "_geoDistance": 640207
    }
  ]
}

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:
curl \
  -X POST 'MEILISEARCH_URL/indexes/restaurants/search' \
  -H 'Content-type:application/json' \
  --data-binary '{
    "filter": "_geoRadius(45.472735, 9.184019, 5000)",
    "sort": ["_geoPoint(45.472735, 9.184019):asc"]
  }'
This is useful when you want to both restrict results to a specific area and present them in order from nearest to farthest.

Geo search overview

Learn about all geo search capabilities in Meilisearch.

Search API reference

Full reference for the search endpoint and sort parameter.