小程序标记点(markers)怎么保持在地图中间?

阅读 17.8k
3 个回答

标记marker可以用control来做,将这个control定位在地图中间就行;
放手后获取地图中心坐标需要用regionchange,他可以判断当前对地图的操作状态,当e.type为end时用mapContext 获取到地图中心的位置;
相关文档:https://mp.weixin.qq.com/debu...
https://mp.weixin.qq.com/debu...

查看接口文档wx.createMapContext(myMap)
wxml:

<map id="myMap"></map>

js:

var mapCtx = wx.createMapContext(myMap)
var latitude,longitude;
mapCtx.getCenterLocation({
    success:function(res){
        latitude = res.latitude;
        longitude = res.longitude;
    }
}) //获取当前地图的中心经纬度
mapCtx.includePoints({
    padding:[10],
    points:[{
        latitude:latitude 
        longitude:longitude
    }]
})
mapCtx.translateMarker({
     markerId: 0,
     autoRotate: true,
     duration: 1000,
     destination: {
        latitude:latitude,
        longitude:longitude,
     },
     animationEnd() {
        console.log('animation end')
     }
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题