May 18, 2021 WeChat Mini Program Development Document
MapContext
wx.createMapContext
MapContext
id
a
map
which manipulates the
map
component.
Gets the latitude and longitude of the center of the current map.
Returned
gcj02
coordinate system, which
can be used for wx.openLocation().
Move the center of the map to the current anchor point, and set the map
show-location
to
true
2.8.0 supports
moving the map center to a specified location.
Pan
marker
with animation
Zoom the field of view to show all latitudes and longitudes
Gets the field of view of the current map
Gets the rotation angle of the current map
Gets the tilt angle of the current map
Gets the zoom level of the current map
Set the map center point offset, growing back down, screen scale range (0.25 to 0.75), default offset is 0.5, 0.5
Remove the personalization layer.
Add a personalized layer.
<!-- map.wxml -->
<map id="myMap" show-location />
<button type="primary" bindtap="getCenterLocation">获取位置</button>
<button type="primary" bindtap="moveToLocation">移动位置</button>
<button type="primary" bindtap="translateMarker">移动标注</button>
<button type="primary" bindtap="includePoints">缩放视野展示所有经纬度</button>
// map.js
Page({
onReady: function (e) {
// 使用 wx.createMapContext 获取 map 上下文
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,
}]
})
}
})