---
name: "getLocation"
mode: "kit"
versionRequirements:
  - { name: "MapKit", version: "1.0.6" }
platform:
  - "iOS"
  - "Android"
async: true
title: "ty.map.getLocation"
---

## getLocation

> [VERSION] MapKit >= 1.0.6

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Get the current location and speed

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `type` | `string` | Yes | - | `1.0.6` | wgs84 returns GPS coordinates; gcj02 returns coordinates usable with openLocation |
| `altitude` | `boolean` | Yes | - | `1.0.6` | Passing true returns altitude information. Because obtaining altitude requires higher precision, it will slow the API response. |
| `isHighAccuracy` | `boolean` | Yes | - | `1.0.6` | Enable high-accuracy location |
| `highAccuracyExpireTime` | `number` | Yes | - | `1.0.6` | High-accuracy location timeout (ms). Returns the highest precision within the specified time; set this to 3000 ms or higher for high-accuracy to take effect. |
| `complete` | `() => void` | No | - | - | Callback invoked when the API call completes (runs on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback invoked on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Callback invoked on failed API call |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `latitude` | `number` | `3.0.5` | Latitude, range -90 to 90; negative values indicate south. |
| `longitude` | `number` | `3.0.5` | Longitude, range -180 to 180; negative values indicate west. |
| `speed` | `number` | `3.0.5` | Speed, in m/s |
| `accuracy` | `number` | `3.0.5` | Location accuracy |
| `altitude` | `number` | `3.0.5` | Altitude, in m |
| `verticalAccuracy` | `number` | `3.0.5` | Vertical accuracy, in m (unavailable on Android, returns 0) |
| `horizontalAccuracy` | `number` | `3.0.5` | Horizontal accuracy, in m |
| `cityName` | `string` | `3.0.5` | City name |
| `streetName` | `string` | `3.0.5` | Street name |
| `address` | `string` | `3.0.5` | Location name; historically, iOS returned an Array type; use the formatAddress field instead. |
| `formatAddress` | `string` | `3.6.0` | Formatted address |
| `countryCode` | `string` | `3.1.0` | Country code |
| `postalCode` | `string` | `3.1.0` | Postal code |
| `countryName` | `string` | `3.1.1` | Country name |
| `province` | `string` | `3.1.1` | Province name |
| `district` | `string` | `3.1.1` | District/county name, secondary region name |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extensions |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Extended error code |
| `errorMsg` | `string` | Extended error information |


### Examples

```tsx
ty.map.getLocation({
  type: "gcj02",
  altitude: false,
  isHighAccuracy: false,
  highAccuracyExpireTime: 3000,
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
