关于定位、marker标识、线路规划等可移步上篇博客
公司在开发小程序用于设备定位位置的获取操作,但在实际使用中,并没有开启高精度定位功能,如果此时客户需要详细定位操作,可以采取手动点击地图实现定位功能。
关于获取地图中心点和显示方面,我之前的博客做了相关的说明,此处不做太多的阐述。
<map class="map" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" show-location="true" bindtap='mapclick'></map>需要点击地图获取点击处的经纬度信息,所以需要给 map组件绑定点击事件
bindtap='mapclick'其次,在相应的js中做事件绑定操作
mapclick: function() {}需要得到点击处的经纬度信息,我们还需要依赖微信小程序的一个api实现操作。微信小程序开发文档
wx.chooseLocation(object)详细代码
onReady: function (e) { this.mapCtx = wx.createMapContext('map') }, mapclick: function() { var that = this; console.log("地图点击"); wx.chooseLocation({ success: function(res) { console.log("地图点击事件:" + JSON.stringify(res)); var user_longitude = res.longitude; var user_lagitude = res.latitude; var user_address = res.address; var nowAddress = {}; nowAddress["name"] = res.name; nowAddress["desc"] = res.address; that.setData({ lagitude: user_lagitude, longitude: user_longitude, addressName: user_address, textData: nowAddress, }); //移动marker that.mapCtx.moveToLocation(); }, fail: function(res) { console.log("点击地图fail:" + JSON.stringify(res)); }, complete: function(res) { // complete console.log("点击地图complete:" + JSON.stringify(res)); } }) },