MapContext

    通过 跟一个 map 组件绑定,操作对应的 组件。

    获取当前地图中心的经纬度。返回的是 gcj02 坐标系,可以用于 wx.openLocation()

    MapContext.moveToLocation(Object object)

    平移marker,带动画

    MapContext.includePoints(Object object)

    缩放视野展示所有经纬度

    MapContext.getRotate()

    获取当前地图的旋转角

    获取当前地图的倾斜角

    MapContext.getScale()

    示例代码

    1. // map.js
    2. Page({
    3. onReady: function (e) {
    4. // 使用 wx.createMapContext 获取 map 上下文
    5. this.mapCtx = wx.createMapContext('myMap')
    6. },
    7. getCenterLocation: function () {
    8. success: function(res){
    9. console.log(res.longitude)
    10. console.log(res.latitude)
    11. }
    12. })
    13. },
    14. this.mapCtx.moveToLocation()
    15. },
    16. translateMarker: function() {
    17. this.mapCtx.translateMarker({
    18. markerId: 0,
    19. autoRotate: true,
    20. duration: 1000,
    21. destination: {
    22. latitude:23.10229,
    23. longitude:113.3345211,
    24. animationEnd() {
    25. console.log('animation end')
    26. }
    27. },
    28. includePoints: function() {
    29. this.mapCtx.includePoints({
    30. padding: [10],
    31. points: [{
    32. latitude:23.10229,
    33. longitude:113.3345211,
    34. }, {
    35. latitude:23.00229,
    36. longitude:113.3345211,
    37. }]
    38. })
    39. }