API Reference / API Parameters / aroundLatLngViaIP
Type: boolean
Engine default: false
Parameter syntax
'aroundLatLngViaIP' => true|false

Can be used in these methods:

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:

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'
]);
Did you find this page helpful?