2018年12月27日 截至当前我并没有找到bindmarkertap 回调时获取到坐标的方法。
最后解决方案请求后端获取到回调ID的坐标。
实现功能导航。
源码:
//标记点击事件
bindmarkertap: function (e) {
let that=this
hotapp.request({
useProxy: true,
url: app.globalData.url + '/map/bicycling/' + e.markerId,
data: {},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: {}, // 设置请求的 header
success: (res) => {
let t = res.data
wx.getLocation({
type: 'gcj02',// 默认wgs84
success: function (res) {
let f = res.latitude+','+res.longitude
//传入坐标 地图划线
that.bicycling(f,t)
}
});
}
})
}
/**
* 纬度,经度
* f出发点坐标
* t到达坐标
*/
bicycling: function (f,t) {
var _this = this;
//网络请求设置
hotapp.request({
useProxy: true,
url: 'https://apis.map.qq.com/ws/direction/v1/bicycling/',
data: {
from: f,
to: t,
key:this.data.key
},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: {}, // 设置请求的 header
success: (res) => {
var ret = res.data
if (ret.status != 0) return; //服务异常处理
var coors = ret.result.routes[0].polyline, pl = [];
//坐标解压(返回的点串坐标,通过前向差分进行压缩)
var kr = 1000000;
for (var i = 2; i < coors.length; i++) {
coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
}
//将解压后的坐标放入点串数组pl中
for (var i = 0; i < coors.length; i += 2) {
pl.push({ latitude: coors[i], longitude: coors[i + 1] })
}
//设置polyline属性,将路线显示出来
_this.setData({
polyline: [{
points: pl,
color: '#FF0000DD',
width: 5
}]
})
}
})
}
如果有更好的办法请告诉我