MapContext
通过 跟一个 map 组件绑定,操作对应的 组件。
获取当前地图中心的经纬度。返回的是 gcj02 坐标系,可以用于 wx.openLocation()
MapContext.moveToLocation(Object object)
平移marker,带动画
MapContext.includePoints(Object object)
缩放视野展示所有经纬度
MapContext.getRotate()
获取当前地图的旋转角
获取当前地图的倾斜角
MapContext.getScale()
示例代码
// map.js
Page({
onReady: function (e) {
// 使用 wx.createMapContext 获取 map 上下文
this.mapCtx = wx.createMapContext('myMap')
},
getCenterLocation: function () {
success: function(res){
console.log(res.longitude)
console.log(res.latitude)
}
})
},
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,
}]
})
}