Skip to main content
The _geoBoundingBox filter returns documents located within a rectangle defined by its top-left and bottom-right coordinates. This is especially useful for map-based interfaces where you want to display results that fit within the current viewport.

Syntax

_geoBoundingBox([topLeftLat, topLeftLng], [bottomRightLat, bottomRightLng])
ParameterTypeDescription
topLeftLatFloatLatitude of the top-left corner (northern boundary)
topLeftLngFloatLongitude of the top-left corner (western boundary)
bottomRightLatFloatLatitude of the bottom-right corner (southern boundary)
bottomRightLngFloatLongitude of the bottom-right corner (eastern boundary)
The first coordinate pair defines the top-left (northwest) corner of the rectangle, and the second defines the bottom-right (southeast) corner. This means:
  • topLeftLat should be greater than bottomRightLat
  • topLeftLng should be less than bottomRightLng

Filter by bounding box

The following example searches for restaurants within a bounding box covering central Milan:
curl \
  -X POST 'MEILISEARCH_URL/indexes/restaurants/search' \
  -H 'Content-type:application/json' \
  --data-binary '{ "filter": "_geoBoundingBox([45.494181, 9.214024], [45.449484, 9.179175])" }'
Meilisearch returns all documents with a _geo location inside the specified rectangle:
{
  "hits": [
    {
      "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": 0
    },
    {
      "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": 0
    }
  ]
}
When using _geoBoundingBox without _geoRadius or _geoPoint sorting, the _geoDistance field is 0 because there is no reference point to calculate distance from.

Use with map-based UIs

Bounding box filters work well with interactive maps. When a user pans or zooms the map, read the visible bounds from your map library and pass them directly to Meilisearch. For example, with a JavaScript map library:
// Get the current map bounds
const bounds = map.getBounds();
const ne = bounds.getNorthEast();
const sw = bounds.getSouthWest();

// Search for results in the visible area
const results = await client.index('restaurants').search('', {
  filter: `_geoBoundingBox([${ne.lat}, ${sw.lng}], [${sw.lat}, ${ne.lng}])`
});

Combine with other filters

You can combine _geoBoundingBox with any other filter using AND and OR operators:
curl \
  -X POST 'MEILISEARCH_URL/indexes/restaurants/search' \
  -H 'Content-type:application/json' \
  --data-binary '{
    "filter": "_geoBoundingBox([45.494181, 9.214024], [45.449484, 9.179175]) AND type = pizza"
  }'

Geo search overview

Learn about all geo search capabilities in Meilisearch.

Search API reference

Full reference for the search endpoint and filter parameter.