# MapContext

MapContext instance, which can be obtained by wx.createMapContext.

mapContext is bound to a <map/> component by id, to operate the corresponding <map/> component.

# Method

# MapContext.getCenterLocation()

Obtain the altitude and longitude of the current map center. The gcj02 coordinate system is returned, which can be used for wx.openLocation()

# MapContext.moveToLocation()

Move the center of the map to the current set position. Needs to be used in coordination with the map component's show-location

# MapContext.translateMarker(Object object)

Translation market, animated

# MapContext.includePoints(Object object)

Scale the field of view to display all latitude and longitude degrees

# MapContext.getRegion()

Acquire the scope of the field of view of the current map

# MapContext.getScale()

Acquire the degree of scaling of the current map

# Sample code

Preview with Developer Tool

<!-- map.wxml -->
<map id="myMap" show-location />

<button type="primary" bindtap="getCenterLocation">Get location</button>
<button type="primary" bindtap="moveToLocation">Move location</button>
<button type="primary" bindtap="translateMarker">Move marker</button>
<button type="primary" bindtap="includePoints">Scale the view to display all latitudes and longitudes</button>
// map.js
Page({
  onReady: function (e) {
    // Use wx.createMapContext to obtain the map context
    this.mapCtx = wx.createMapContext('myMap')
  },
  getCenterLocation: function () {
    this.mapCtx.getCenterLocation({
      success: function(res){
        console.log(res.longitude)
        console.log(res.latitude)
      }
    })
  },
  moveToLocation: function () {
    this.mapCtx.moveToLocation()
  },
  translateMarker: function() {
    this.mapCtx.translateMarker({
      markerId: 0,
      autoRotate: true,
      duration: 1000,
      destination: {
        latitude:23.10229,
        longitude:113.3345211,
      },
      animationEnd() {
        console.log('animation end')
      }
    })
  },
  includePoints: function() {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude:23.10229,
        longitude:113.3345211,
      }, {
        latitude:23.00229,
        longitude:113.3345211,
      }]
    })
  }
})