> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# aroundLatLngViaIP

> Determine the center for location based search from the user's IP address

export const Setting = ({type, default: defaultValue, defaultNote, scope, min, max, formerly}) => {
  const renderedDefault = defaultValue === '' ? '""' : defaultValue;
  const renderedNote = defaultNote ? `(${defaultNote})` : '';
  return <ul>
      <li><strong>Type:</strong> <code>{type}</code></li>
      <li><strong>Default:</strong> <code>{renderedDefault}</code>{renderedNote}</li>
      {min && <li><strong>Min:</strong> <code>{min}</code></li>}
      {max && <li><strong>Max:</strong> <code>{max}</code></li>}
      <li><strong>Scope:</strong> <a href="/doc/api-reference/api-parameters"><code>{scope}</code></a></li>
      {formerly && <li>
          <strong>Deprecated name:</strong> <code>{formerly}</code>
        </li>}
    </ul>;
};

<Setting type="boolean" default="false" scope="search" />

The `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`](/doc/api-reference/api-parameters/aroundLatLng).

To learn more, see [Geo location](/doc/guides/managing-results/refine-results/geolocation).

## Usage

* For server-side requests, set the `X-Forwarded-For` header with the user's IP address.
  Otherwise, every search will be around the location of your server.

* You can adjust precision using [`aroundPrecision`](/doc/api-reference/api-parameters/aroundPrecision),
  but accuracy varies—especially when IP addresses are mapped to large areas.

* This parameter is **ignored** if [`insideBoundingBox`](/doc/api-reference/api-parameters/insideBoundingBox) or [`insidePolygon`](/doc/api-reference/api-parameters/insidePolygon) is used.

## Example

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SearchSingleIndexAsync<Hit>(
        "INDEX_NAME",
        new SearchParams(new SearchParamsObject { AroundLatLngViaIP = true })
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.searchSingleIndex(
        indexName: "INDEX_NAME",
        searchParams: SearchParamsObject(
          aroundLatLngViaIP: true,
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
        "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
        search.NewEmptySearchParamsObject().SetAroundLatLngViaIP(true))))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      SearchResponse response = client.searchSingleIndex("INDEX_NAME", new SearchParamsObject().setAroundLatLngViaIP(true), Hit.class);
      ```

      ```js JavaScript theme={"system"}
      const response = await client.searchSingleIndex({
        indexName: 'indexName',
        searchParams: { aroundLatLngViaIP: true },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = SearchParamsObject(aroundLatLngViaIP = true),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->searchSingleIndex(
          'INDEX_NAME',
          ['aroundLatLngViaIP' => true,
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.search_single_index(
          index_name="INDEX_NAME",
          search_params={
              "aroundLatLngViaIP": True,
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.search_single_index(
        "INDEX_NAME",
        Algolia::Search::SearchParamsObject.new(around_lat_lng_via_ip: true)
      )
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = Some(
            SearchParamsObject(
              aroundLatLngViaIP = Some(true)
            )
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response: SearchResponse<Hit> = try await client.searchSingleIndex(
          indexName: "INDEX_NAME",
          searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(aroundLatLngViaIP: true))
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      // 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
      });
      ```

      ```go Go theme={"system"}
      // 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,
      )
      ```

      ```java Java theme={"system"}
      // 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")
      );
      ```

      ```js JavaScript theme={"system"}
      // 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);
        });
      ```

      ```kotlin Kotlin theme={"system"}
      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)
      ```

      ```php PHP theme={"system"}
      $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'
      ]);
      ```

      ```python Python theme={"system"}
      # 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})
      ```

      ```ruby Ruby theme={"system"}
      # 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"
          }
        }
      )
      ```

      ```scala Scala theme={"system"}
      // 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"))
        )
      }
      ```

      ```swift Swift theme={"system"}
      // 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)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
