aroundLatLngViaIP parameter automatically determines a user’s geographic location using their IP address and uses it as the center for geo-based search.
This provides location-aware results without requiring explicit coordinates.
For more information, or if you want to provide explicit coordinates, see aroundLatLng.
To learn more, see Geo location.
Usage
-
For server-side requests, set the
X-Forwarded-Forheader with the user’s IP address. Otherwise, every search will be around the location of your server. -
You can adjust precision using
aroundPrecision, but accuracy varies—especially when IP addresses are mapped to large areas. -
This parameter is ignored if
insideBoundingBoxorinsidePolygonis used.
Example
Current API clients
Current API clients
var response = await client.SearchSingleIndexAsync<Hit>(
"INDEX_NAME",
new SearchParams(new SearchParamsObject { AroundLatLngViaIP = true })
);
final response = await client.searchSingleIndex(
indexName: "INDEX_NAME",
searchParams: SearchParamsObject(
aroundLatLngViaIP: true,
),
);
response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
"INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
search.NewEmptySearchParamsObject().SetAroundLatLngViaIP(true))))
if err != nil {
// handle the eventual error
panic(err)
}
SearchResponse response = client.searchSingleIndex("INDEX_NAME", new SearchParamsObject().setAroundLatLngViaIP(true), Hit.class);
const response = await client.searchSingleIndex({
indexName: 'indexName',
searchParams: { aroundLatLngViaIP: true },
});
var response =
client.searchSingleIndex(
indexName = "INDEX_NAME",
searchParams = SearchParamsObject(aroundLatLngViaIP = true),
)
$response = $client->searchSingleIndex(
'INDEX_NAME',
['aroundLatLngViaIP' => true,
],
);
response = client.search_single_index(
index_name="INDEX_NAME",
search_params={
"aroundLatLngViaIP": True,
},
)
response = client.search_single_index(
"INDEX_NAME",
Algolia::Search::SearchParamsObject.new(around_lat_lng_via_ip: true)
)
val response = Await.result(
client.searchSingleIndex(
indexName = "INDEX_NAME",
searchParams = Some(
SearchParamsObject(
aroundLatLngViaIP = Some(true)
)
)
),
Duration(100, "sec")
)
let response: SearchResponse<Hit> = try await client.searchSingleIndex(
indexName: "INDEX_NAME",
searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(aroundLatLngViaIP: true))
)
Legacy API clients
Legacy API clients
// Replace XX.XXX.XXX.XXX with a real IP address.
// How you retrieve this depends on your stack.
var configuration = new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
{
DefaultHeaders = new Dictionary { { "X-Forwarded-For", "XX.XXX.XXX.XXX" } }
};
SearchClient client = new SearchClient(configuration);
index.Search(new Query("query")
{
AroundLatLngViaIP = true
});
// Replace XX.XXX.XXX.XXX with a real IP address.
// How you retrieve this depends on your stack.
extraHeaders := opt.ExtraHeaders(map[string]string{
"X-Forwarded-For", "XX.XXX.XXX.XXX",
})
res, err := index.Search(
"query",
opt.AroundLatLngViaIP(true),
extraHeaders,
)
// Replace XX.XXX.XXX.XXX with a real IP address.
// How you retrieve this depends on your stack.
index.search(
new Query("query")
.setAroundLatLngViaIP(true),
new RequestOptions()
.addExtraHeader("X-Forwarded-For", "XX.XXX.XXX.XXX")
);
// Replace XX.XXX.XXX.XXX with a real IP address.
// How you retrieve this depends on your stack.
// Only needed on Node.js.
// The header is automatically added for requests made from browsers.
index
.search("query", {
aroundLatLngViaIP: true,
headers: {
"X-Forwarded-For": "XX.XXX.XXX.XXX",
},
})
.then(({ hits }) => {
console.log(hits);
});
val configuration = ConfigurationSearch(
ApplicationID("ALGOLIA_APPLICATION_ID"),
APIKey("ALGOLIA_API_KEY"),
defaultHeaders = mapOf("X-Forwarded-For" to "XX.XXX.XXX.XXX")
)
val client = ClientSearch(configuration)
val index = client.initIndex(IndexName("index_name"))
val query = query("query") {
aroundLatLngViaIP = true
}
index.search(query)
$client = new \Algolia\AlgoliaSearch\SearchClient::create(
'ALGOLIA_APPLICATION_ID',
'ALGOLIA_API_KEY'
);
$index = $client->initIndex('index_name');
// Replace XX.XXX.XXX.XXX with a real IP address.
// How you retrieve this depends on your stack.
$results = $index->search('query', [
'aroundLatLngViaIP' => true,
'X-Forwarded-For' => 'XX.XXX.XXX.XXX'
]);
# Replace XX.XXX.XXX.XXX with a real IP address.
# How you retrieve this depends on your stack.
config = SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
config.headers["X-Forwarded-For"] = "XX.XXX.XXX.XX"
client = SearchClient.create_with_config(config)
index = client.init_index("index_name")
results = index.search("query", {"aroundLatLngViaIP": True})
# Replace XX.XXX.XXX.XXX with a real IP address.
# How you retrieve this depends on your stack.
client = Algolia::Search::Client.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
index = client.init_index("index_name")
results = index.search(
"query",
{
aroundLatLngViaIP: true,
headers: {
:"X-Forwarded-For" => "XX.XXX.XXX.XXX"
}
}
)
// Replace XX.XXX.XXX.XXX with a real IP address.
// How you retrieve this depends on your stack.
client.execute {
search into "myIndex" query Query(
query = Some("query"),
aroundLatLngViaIP = Some(true)
) options RequestsOptions(
extraHeaders = Some(Map("X-Forwarded-For" -> "XX.XXX.XXX.XXX"))
)
}
// Replace XX.XXX.XXX.XXX with a real IP address.
// How you retrieve this depends on your stack.
let configuration = SearchConfiguration(
applicationID: "ALGOLIA_APPLICATION_ID",
apiKey: "ALGOLIA_API_KEY"
)
.set(\.defaultHeaders, to: ["X-Forwarded-For": "XX.XXX.XXX.XXX"])
let client = SearchClient(configuration: configuration)
let index = client.index(withName: "index_name")
let query = Query("query")
.set(\.aroundLatLngViaIP, to: true)
index.search(query: query) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}