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 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.

  • 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

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?