我也遇到同样问题了
map bindRegionchange里setdata设置经纬度导致重复调用//获取位置信息 wx.getLocation({ type: 'gcj02', success: (res) => { let longitude = res.longitude; let latitude = res.latitude; this.setData({ longitude, latitude }); app.globalData.curLocation = res; }, fail: ()=>{ wx.showModal({ title: '提示', content: '定位失败', showCancel: false, }); } });bindRegionchange: function (e) { let {type} = e; if( type == "end"){ this.getCenterLocation(); } },getCenterLocation: function(){ this.mapCtx.getCenterLocation({ success: res => { let {longitude, latitude} = res, coord = { longitude, latitude, }; // this.setData(coord); this.updateMarkers({ longitude, latitude, }) }, }); },我试过加个防抖动也试过吧this.setdata注释过 各位有什么好的解决方法 求组
2018-08-23我也遇到类似问题了,如何得到拖拽地图上起始和结尾两点的位置信息
求教 地图选点距离计算[代码]//index.js[代码][代码]//获取应用实例[代码][代码]const app = getApp()[代码] [代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]name1:[代码][代码]"请输入发货地址"[代码][代码],[代码][代码] [代码][代码]name2:[代码][代码]"请输入收货地址"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onLoad1: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.chooseLocation({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]// name 位置名称[代码][代码] [代码][代码]// address 详细地址[代码][代码] [代码][代码]// latitude 纬度,浮点数,范围为 - 90~90,负数表示南纬[代码][代码] [代码][代码]// longitude 经度,浮点数,范围为 - 180~180,负数表示西经[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]var[代码] [代码]name = res.name;[代码][代码] [代码][代码]var[代码] [代码]address =res.address;[代码][代码] [代码][代码]var[代码] [代码]latitude = res.latitude;[代码][代码] [代码][代码]var[代码] [代码]longitude = res.longitude;[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]name1:name,[代码][代码] [代码][代码]address1:address,[代码][代码] [代码][代码]la1:latitude,[代码][代码] [代码][代码]lo1:longitude[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onLoad2: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.chooseLocation({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]// name 位置名称[代码][代码] [代码][代码]// address 详细地址[代码][代码] [代码][代码]// latitude 纬度,浮点数,范围为 - 90~90,负数表示南纬[代码][代码] [代码][代码]// longitude 经度,浮点数,范围为 - 180~180,负数表示西经[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]var[代码] [代码]name = res.name;[代码][代码] [代码][代码]var[代码] [代码]address = res.address;[代码][代码] [代码][代码]var[代码] [代码]latitude = res.latitude;[代码][代码] [代码][代码]var[代码] [代码]longitude = res.longitude;[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]name2: name,[代码][代码] [代码][代码]address2: address,[代码][代码] [代码][代码]la2: latitude,[代码][代码] [代码][代码]lo2: longitude [代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码] [代码] [代码] [代码] [代码][代码]onLoad3: [代码][代码]function[代码] [代码](options) {[代码][代码] [代码][代码]//[0: (39.928712, 116.393345),1: (39.928722, 116.393853)] 举个栗子[代码][代码] [代码][代码]this[代码][代码].distance(39.928712, 116.393345,39.928722, 116.393853)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]distance: [代码][代码]function[代码] [代码](la1, lo1, la2, lo2) {[代码][代码] [代码][代码]var[代码] [代码]La1 = la1 * Math.PI / 180.0;[代码][代码] [代码][代码]var[代码] [代码]La2 = la2 * Math.PI / 180.0;[代码][代码] [代码][代码]var[代码] [代码]La3 = La1 - La2;[代码][代码] [代码][代码]var[代码] [代码]Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;[代码][代码] [代码][代码]var[代码] [代码]s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));[代码][代码] [代码][代码]s = s * 6378.137;[代码][代码]//地球半径[代码][代码] [代码][代码]s = Math.round(s * 10000) / 10000;[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]s:s[代码][代码] [代码][代码]})[代码][代码] [代码][代码]// return s[代码][代码] [代码][代码]console.log([代码][代码]"计算结果"[代码][代码],s)[代码][代码] [代码][代码]},[代码][代码]})[代码]地图两点 的能位置获取了 计算算距离的代码也找到了 但接下来的就不会了 求教。。。。
2018-08-22