aroundLatLngViaIP
false
'aroundLatLngViaIP' => true|false
Can be used in these methods:
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
Browse,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
BrowseObjects,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
browse index,
search into facet values,
generateSecuredApiKey,
add key,
update key
About this parameter
Search for entries around a central location automatically computed from the user’s IP address, enabling a geographical search within a circular area.
A circle around the central location is automatically computed based on the density of records near that point. The radius will be small if many hits are close to the central location. The less hits near the center, the larger the radius will be.
Only records that fall within the bounds of this circle are returned.
Records are ranked according to their distance from the central location.
If you set getRankingInfo
to true
, each result will include the distance from the central location.
You can adjust the minimum and maximum radius:
- To determine maximum radius, use
aroundRadius
- To determine minimum radius, use
minimumAroundRadius
.
You can set geo search precision with aroundPrecision
, but the accuracy may vary.
For example, a block of IP addresses might be assigned to a whole city and all IPs will use the city center as the central location.
Usage notes
If you’re sending the request from your servers, set the X-Forwarded-For
HTTP header to the user’s IP address to help Algolia determine their central location.
This parameter is ignored if used with insideBoundingBox
or insidePolygon
.
To specify the exact latitude and longitude of the central location, use aroundLatLng
instead.
Examples
Search around user’s IP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$client = new \Algolia\AlgoliaSearch\SearchClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$index = $client->initIndex('index_name');
/*
'94.228.178.246' should be replaced with the actual IP you would like
to search around. Depending on your stack there are multiple ways to get this
information.
*/
$results = $index->search('query', [
'aroundLatLngViaIP' => true,
'X-Forwarded-For' => '94.228.178.246'
]);