效果图:
qqmapsdk = new QQMapWX({
key: 'xxxxx'
});
qqmapsdk.direction({
mode: 'driving',
from: {
latitude: '30.951471',
longitude: '121.481774'
},
to: {
latitude: '30.952991',
longitude: '121.494681'
},
success: (res) => {
console.log(res);
let data = res.result;
if(data.routes && data.routes[0] && data.routes[0].steps){
var coors = res.result.routes[0].polyline
// 解压坐标点
for (var i = 2; i < coors.length; i++){
coors[i] = coors[i - 2] + coors[i] / 1000000
}
// 将解压后的坐标点串进行拼接成polyline想要的样子
var coors_new=[]
for(var j = 0; j < coors.length; j++){
coors_new.push({
latitude: parseFloat(coors[j]),
longitude: parseFloat(coors[j+1])
})
j++;
}
}
this.setData({
polyline: [{
points: coors_new,
color: "#0091ff",
width: 2,
dottedLine: true
}]
});
},
fail: function (res) {
console.log(res);
},
})