---
name: "MapContext.moveToLocation"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.21.8" }
title: "MapContext.moveToLocation - 将地图中心移置当前定位点"
---

## MapContext.moveToLocation

> [VERSION] Base Library >= 2.21.8

### Description

Move the map center to the current location; the map component must have show-location set to true

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `option` | `MoveToLocationOption` | Yes | Location options |

### Return Value

None


### Referenced Types

##### `interface` MoveToLocationOption

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `longitude` | `number` | No | Longitude |
| `latitude` | `number` | No | Latitude |
| `success` | `() => void` | No | Callback invoked on successful API call |
| `fail` | `(result: MapFailResult) => void` | No | Callback on failure |
| `complete` | `() => void` | No | Callback on complete (success or failure) |

##### `interface` MapFailResult

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


### Examples

#### Move to current location

```ts
const mapCtx = ty.createMapContext('myMap');
mapCtx.moveToLocation({
  success() {
    console.log('Moved to current location');
  },
});
```

#### Move to specified latitude and longitude

```ts
const mapCtx = ty.createMapContext('myMap');
mapCtx.moveToLocation({
  longitude: 120.0,
  latitude: 30.0,
  success() {
    console.log('Moved to the specified location');
  },
});
```
