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 given location automatically computed from the requester’s IP address.
By computing a central geolocation (from an IP), this has three consequences:
- a radius / circle is computed automatically, based on the density of the records near the point defined by this setting
- only records that fall within the bounds of the circle are returned
- records are ranked according to the distance from the center of the circle
The precision of geo search should be set with aroundPrecision
, but the accuracy of the localized IP may vary.
As an example, an IP block might be assigned to a whole city. In this case, all IPs will have the center of the city as coordinates.
Usage notes
-
With this setting, you are using the end user’s IP to define a central axis point of a circle in geo-coordinates.
-
Algolia automatically calculates the size of the circular radius around this central axis.
- To control the precise size of the radius, you would use
aroundRadius
. - To control a minimum size, you would use
minimumAroundRadius
.
- To control the precise size of the radius, you would use
-
If you are sending the request from your servers, you must set the
X-Forwarded-For
HTTP header with the front-end user’s IP address for it to be used as the basis for the computation of the search location. -
Note: This setting differs from
aroundLatLng
, which allows you to specify the exact latitude and longitude of the center of the circle. -
This parameter will be ignored if used along with
insideBoundingBox
orinsidePolygon
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'
]);