/**
* 视野发生变化时触发:见页面bindregionchange事件
*/
regionchange: function (e) {
//console.log("regionchange_type="+e.type)
e.type == 'end' ? this.getLngLat() : '';
},
/**
* 获取中间点的经纬度,并mark出来
*/
getLngLat() {
let that = this;
this.mapCtx = wx.createMapContext("map"); //与xml里面的<map id="{{map}}">相对应
this.mapCtx.getCenterLocation({
success: function (res) {
//console.log("getCenterLocation=" + JSON.stringify(res))
that.setData({
markers_ic: [{
id: "1",
iconPath: "/pages/inc/images/ic_location.png",
longitude: res.longitude,
latitude: res.latitude,
width: 20,
height: 20
}]
})
//自己 的逻辑代码把(res.longitude,res.latitude,)传进
that.getcurrentparking(res.longitude, res.latitude)
}
})
},
本文介绍了一种在小程序中处理地图视野变化事件的方法,通过监听regionchange事件,获取地图中心点的经纬度,并在地图上标记该位置。具体实现包括创建地图上下文,调用getCenterLocation方法获取坐标,然后使用setData更新页面数据,展示标记。
3344

被折叠的 条评论
为什么被折叠?



