---
name: "MapContext.getCenterLocation"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.21.8" }
title: "MapContext.getCenterLocation - 获取当前地图中心的经纬度"
---

## MapContext.getCenterLocation

> [VERSION] Base Library >= 2.21.8

### Description

Get the latitude and longitude at the current map center

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `option` | `GetCenterLocationOption` | Yes | Callback options |

### Return Value

None


### Referenced Types

##### `interface` GetCenterLocationOption

| Property | Type | Description |
| --- | --- | --- |
| `iconPath` | `string` | Icon path; supports network URLs and code package paths |
| `clear` | `boolean` | Whether to clear all markers on the map first |
| `success` | `(result: GetCenterLocationResult) => void` | Callback invoked on successful API call |
| `fail` | `(result: MapFailResult) => void` | Callback on failure |
| `complete` | `() => void` | Callback on complete (success or failure) |

##### `interface` GetCenterLocationResult

| Property | Type | Description |
| --- | --- | --- |
| `longitude` | `number` | Longitude |
| `latitude` | `number` | Latitude |

##### `interface` MapFailResult

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


### Examples

#### Get center latitude and longitude

```ts
const mapCtx = ty.createMapContext('myMap');
mapCtx.getCenterLocation({
  success(res) {
    console.log('Center longitude', res.longitude);
    console.log('Center latitude', res.latitude);
  },
});
```
