> ## Documentation Index
> Fetch the complete documentation index at: https://use-any-hook-d92674ab.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# useGeoLocation

> Retrieve the user's current geographic location with useGeoLocation.

#### **Install**

```bash npm theme={null}
npm i use-any-hook
```

#### **Description**

The `useGeoLocation` hook provides a simple way to retrieve the user's current geographic location. This is useful for applications that need to display or use location-based data, such as maps, weather information, or location-based services. The hook handles the process of fetching the location and provides both the location data and any potential errors.

#### **Parameters**

This hook does not require any parameters.

#### **Return Values:**

| Name     | Type   | Description                                                                                            |
| -------- | ------ | ------------------------------------------------------------------------------------------------------ |
| location | object | The location object containing geographic coordinates (`latitude` and `longitude`) and other metadata. |
| error    | object | An error object if there was an issue retrieving the location, or `null` if no errors occurred.        |

#### **Example**

```javascript useGeoLocation.example.tsx theme={null}
import { useGeoLocation } from "use-any-hook";

function MyComponent() {
  const { location, error } = useGeoLocation();

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return (
    <div>
      {location ? (
        <div>
          Latitude: {location.coords.latitude}, Longitude:{" "}
          {location.coords.longitude}
        </div>
      ) : (
        <div>Fetching location...</div>
      )}
    </div>
  );
}
```
