Syntax
The _geoRadius filter returns documents located within a circular area defined by a center point and a radius. This is the most common geo filter, useful for “find nearby” features like store locators, restaurant finders, or service area lookups.
Syntax
_geoRadius(lat, lng, distanceInMeters)
| Parameter | Type | Description |
|---|---|---|
lat |
Float | Latitude of the center point |
lng |
Float | Longitude of the center point |
distanceInMeters |
Integer | Radius of the search area in meters |
The distance is always expressed in meters. For example, use 2000 for a 2 km radius or 500 for 500 meters.
Filter by radius
The following example searches for restaurants within 2 km of central Milan (latitude 45.472735, longitude 9.184019):
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
curl \
-X POST 'MEILISEARCH_URL/indexes/restaurants/search' \
-H 'Authorization: Bearer API_KEY' \
-H 'Content-type:application/json' \
--data-binary '{ "filter": "_geoRadius(45.472735, 9.184019, 2000)" }'
client.index('restaurants').search('', {
filter: ['_geoRadius(45.472735, 9.184019, 2000)'],
})
client.index('restaurants').search('', {
'filter': '_geoRadius(45.472735, 9.184019, 2000)'
})
$client->index('restaurants')->search('', [
'filter' => '_geoRadius(45.472735, 9.184019, 2000)'
]);
SearchRequest searchRequest = SearchRequest.builder().q("").filter(new String[] {"_geoRadius(45.472735, 9.184019, 2000)"}).build();
client.index("restaurants").search(searchRequest);
client.index('restaurants').search('', { filter: '_geoRadius(45.472735, 9.184019, 2000)' })
resp, err := client.Index("restaurants").Search("", &meilisearch.SearchRequest{
Filter: "_geoRadius(45.472735, 9.184019, 2000)",
})
SearchQuery filters = new SearchQuery() { Filter = "_geoRadius(45.472735, 9.184019, 2000)" };
var restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("", filters);
let results: SearchResults<Restaurant> = client
.index("restaurants")
.search()
.with_filter("_geoRadius(45.472735, 9.184019, 2000)")
.execute()
.await
.unwrap();
let searchParameters = SearchParameters(
filter: "_geoRadius(45.472735, 9.184019, 2000)"
)
client.index("restaurants").search(searchParameters) { (result: Result<Searchable<Restaurant>, Swift.Error>) in
switch result {
case .success(let searchResult):
print(searchResult)
case .failure(let error):
print(error)
}
}
await client.index('restaurants').search(
'',
SearchQuery(
filterExpression: Meili.geoRadius(
(lat: 45.472735, lng: 9.184019),
2000,
),
),
);
Meilisearch returns all documents with a _geo location inside the specified circle:
{
"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": 1532
},
{
"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": 1343
}
]
}
Understanding _geoDistance
When you use _geoRadius, Meilisearch automatically includes a _geoDistance field in each result. This value represents the distance in meters between the document’s location and the center point of your radius filter.
_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.
Combine with other filters
You can combine _geoRadius with any other filter using AND and OR operators. The following example finds only pizzerias within 2 km of central Milan:
cURL
JS
Python
PHP
Java
Ruby
Go
C#
Rust
Swift
Dart
curl \
-X POST 'MEILISEARCH_URL/indexes/restaurants/search' \
-H 'Authorization: Bearer API_KEY' \
-H 'Content-type:application/json' \
--data-binary '{ "filter": "_geoRadius(45.472735, 9.184019, 2000) AND type = pizza" }'
client.index('restaurants').search('', {
filter: ['_geoRadius(45.472735, 9.184019, 2000) AND type = pizza'],
})
client.index('restaurants').search('', {
'filter': '_geoRadius(45.472735, 9.184019, 2000) AND type = pizza'
})
$client->index('restaurants')->search('', [
'filter' => '_geoRadius(45.472735, 9.184019, 2000) AND type = pizza'
]);
SearchRequest searchRequest = SearchRequest.builder().q("").filter(new String[] {"_geoRadius(45.472735, 9.184019, 2000) AND type = pizza"}).build();
client.index("restaurants").search(searchRequest);
client.index('restaurants').search('', { filter: '_geoRadius(45.472735, 9.184019, 2000) AND type = pizza' })
resp, err := client.Index("restaurants").Search("", &meilisearch.SearchRequest{
Filter: "_geoRadius(45.472735, 9.184019, 2000) AND type = pizza",
})
SearchQuery filters = new SearchQuery()
{
Filter = new string[] { "_geoRadius(45.472735, 9.184019, 2000) AND type = pizza" }
};
var restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("restaurants", filters);
let results: SearchResults<Restaurant> = client
.index("restaurants")
.search()
.with_filter("_geoRadius(45.472735, 9.184019, 2000) AND type = pizza")
.execute()
.await
.unwrap();
let searchParameters = SearchParameters(
filter: "_geoRadius(45.472735, 9.184019, 2000) AND type = pizza"
)
client.index("restaurants").search(searchParameters) { (result: Result<Searchable<Restaurant>, Swift.Error>) in
switch result {
case .success(let searchResult):
print(searchResult)
case .failure(let error):
print(error)
}
}
await client.index('restaurants').search(
'',
SearchQuery(
filterExpression: Meili.and([
Meili.geoRadius(
(lat: 45.472735, lng: 9.184019),
2000,
),
Meili.attr('type').eq('pizza'.toMeiliValue())
]),
),
);
{
"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": 1532
}
]
}
Common radius values
| Use case | Radius |
|---|---|
| Walking distance | 1000 (1 km) |
| Short drive | 5000 (5 km) |
| City-wide | 15000 (15 km) |
| Regional | 50000 (50 km) |
Geo search overview
Learn about all geo search capabilities in Meilisearch.
Search API reference
Full reference for the search endpoint and filter parameter.
