---
name: "getLocation"
mode: "kit"
versionRequirements:
  - { name: "MapKit", version: "1.0.6" }
  - { name: "@ray-js/ray", version: "1.2.10" }
platform:
  - "iOS"
  - "Android"
async: true
title: "map.getLocation"
---

## getLocation

> [VERSION] MapKit >= 1.0.6 | @ray-js/ray >= 1.2.10

> [PLATFORM] iOS, Android

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

### Description

Get 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. Because obtaining altitude requires higher accuracy, 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 possible accuracy within the specified time. High-accuracy positioning only takes effect when this value is greater than 3000 ms. |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### 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, unit: m/s |
| `accuracy` | `number` | `3.0.5` | Location accuracy |
| `altitude` | `number` | `3.0.5` | Altitude, unit: m |
| `verticalAccuracy` | `number` | `3.0.5` | Vertical accuracy, in meters (not available on Android, returns 0) |
| `horizontalAccuracy` | `number` | `3.0.5` | Horizontal accuracy, in meters |
| `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; 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 (second-level administrative region) |

#### fail callback parameters

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

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

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Examples

#### Basic call

```tsx
import { map } from '@ray-js/ray'

const { getLocation } = map;

getLocation({
  type: 'gcj02',
  altitude: false,
  isHighAccuracy: false,
  highAccuracyExpireTime: 3000,
  success: (result) => {
    console.log('getLocation success', result);
  },
  fail: (error) => {
    console.log('getLocation fail', error.errorMsg);
  },
});
```
