---
name: "MapContext.moveAlong"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.21.8" }
title: "MapContext.moveAlong - 沿指定路径移动 marker"
---

## MapContext.moveAlong

> [VERSION] Base Library >= 2.21.8

> 💡 Triggers a callback when the animation completes. If moveAlong is called again on the same marker while an animation is in progress, the previous animation will be interrupted.

### Description

Move a marker along a specified path, for scenarios such as track playback

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `option` | `MoveAlongOption` | Yes | Path movement options |

### Return Value

None


### Referenced Types

##### `interface` MoveAlongOption

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `markerId` | `number` | Yes | ID of the marker |
| `path` | `MapPosition[]` | Yes | Coordinate sequence of the movement path |
| `duration` | `number` | Yes | Duration of the smooth movement, in ms |
| `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` MapPosition

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

##### `interface` MapFailResult

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


### Examples

#### Trajectory playback

```ts
const mapCtx = ty.createMapContext('myMap');
mapCtx.moveAlong({
  markerId: 1,
  path: [
    { longitude: 120.0, latitude: 30.0 },
    { longitude: 120.5, latitude: 30.5 },
    { longitude: 121.0, latitude: 31.0 },
  ],
  duration: 5000,
  success() {
    console.log('Track playback completed');
  },
});
```
