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

# my.getLocation

> Get the current geographic location.

Get the user's current location coordinates.

## Parameters

| Property     | Type     | Required | Description                                                                  |
| ------------ | -------- | -------- | ---------------------------------------------------------------------------- |
| type         | Number   | No       | `0`: default, get the longitude and latitude                                 |
| cacheTimeout | Number   | No       | Longitude and latitude location cache expiry time in seconds. Default is 30s |
| success      | Function | No       | Callback with location                                                       |
| fail         | Function | No       | Callback on failure                                                          |
| complete     | Function | No       | Callback that always executes                                                |

## Success Callback

| Property  | Type   | Description    |
| --------- | ------ | -------------- |
| longitude | String | Longitude      |
| latitude  | String | Latitude       |
| accuracy  | String | Accuracy, in m |

## Error Codes

| Error | Description                                           | Solution                                      |
| ----- | ----------------------------------------------------- | --------------------------------------------- |
| 11    | Make sure the location related right has been enabled | Prompt the user to enable location permission |
| 12    | Network abnormity, try again later                    | Prompt the user to check the current network  |
| 13    | Location failure, try again later                     | —                                             |
| 14    | Service location timeout                              | Prompt the user to try again                  |

## Code Example

```javascript theme={null}
my.getLocation({
  success: (res) => {
    console.log('Lat:', res.latitude);
    console.log('Lng:', res.longitude);
  }
});
```

## Related APIs

<CardGroup cols={2}>
  <Card title="my.openLocation" icon="map-pin" href="/jsapi/location/my.openLocation">
    Open location in map
  </Card>

  <Card title="my.chooseLocation" icon="location-crosshairs" href="/jsapi/location/my.chooseLocation">
    Choose a location
  </Card>
</CardGroup>
