---
name: "MapContext"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.21.8" }
title: "MapContext"
---

## MapContext

> [VERSION] Base Library >= 2.21.8

> 💡 MapContext is bound to a map component by id and controls that component

### Description

MapContext instance, obtainable via ty.createMapContext

### Parameters

None


### Return Value

Type: `MapContext`

MapContext instance

#### Methods

| Method | Description |
| --- | --- |
| `addMarkers` | Add marker |
| `getCenterLocation` | Get the latitude and longitude at the current map center |
| `getScale` | Get the current map zoom level |
| `moveToLocation` | Move the map center to the current location; the map component must have show-location set to true |
| `removeMarkers` | Remove marker |
| `moveAlong` | Move a marker along a specified path, for scenarios such as track playback |

### Examples

#### Basic usage

```ts
Page({
  onReady() {
    const mapCtx = ty.createMapContext('myMap');
    mapCtx.getScale({
      success(res) {
        console.log('Current zoom level', res.scale);
      },
    });
  },
});
```
