aroundLatLngViaIP
false
'aroundLatLngViaIP' => true|false
Can be used in these methods:
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
searchAsync,
browseAsync,
searchForFacetValues
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
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.
-
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 or insidePolygon
-
We currently only support IPv4 addresses. If the end user has an IPv6 address, this parameter won’t work as intended.
Examples
Search around user’s IP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
'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.
*/
$ip = '94.228.178.246';
$client = new \Algolia\AlgoliaSearch\Client::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$client->setExtraHeader('X-Forwarded-For', $ip);
$index = $client->initIndex('index_name');
$results = $index->search('query', [
'aroundLatLngViaIP' => true
]);