时间:2019-05-04 来源:小程序工厂
可以提供一下简单的代码片段吗
markertap: function(e) { //点击地图上的标记点时画出路线
let that2 = this;
var markerID = e.markerId; //获取当前点击markers数组里的经纬度
// console.log(markerID)
var Markerng = that2.data.markers[markerID-1].callout.content;
console.log(Markerng)
var endlat = that2.data.markers[markerID - 1].latitude;
var endlog = that2.data.markers[markerID - 1].longitude
var fromlat = that2.data.lat
var fromlog = that2.data.log
var dis
var dur
that2.setData({
MarkerNeirong: Markerng
})
wx.request({
url: 'https://apis.map.qq.com/ws/direction/v1/walking/?from=' + fromlat + ',' + fromlog + '&to=' + endlat + ',' + endlog + '&output=json&callback=cb&key=' + qqMapKey,
success: function (res) {
coors = res.data.result.routes[0].polyline
// console.log(res)
dis = res.data.result.routes[0].distance
dur = res.data.result.routes[0].duration
for (var i = 2; i < coors.length; i++) {
coors[i] = coors[i - 2] + coors[i] / 1000000
}
// console.log(coors)
//划线
var b = [];
for (var i = 0; i < coors.length; i = i + 2) {
b[i / 2] = {
latitude: coors[i], longitude: coors[i + 1]
};
// console.log(b[i / 2])
}
that2.setData({
polyline: [{
points: b,
color: "#99FF00",
width: 4,
dottedLine: false
}],
distance: dis,
duration: dur
},
)
}
})
},
onLoad: function() {
var that = this;
wx.getLocation({
success: function(res) {
var latitude = res.latitude
var longtitude = res.longitude
console.log(latitude,longtitude)
that.setData({
lat: latitude,
log: longtitude
})
},
})
}
关键是前几天还能用的,这两天就不能用了。
有没有大神帮我看看是怎么回事啊