做的是定位当前位置并且显示行动轨迹,存放轨迹polyline的数据console可以看到数据但是在地图上面只显示当前定位不显示轨迹
onLoad: function (options) {
console.log(options.id)
var that = this;
wx.request({
url: 'http://。。。。。。:8000/position/findTheConcreteTrace/' + app.globalData.userid + '/' + options.id,
method: 'GET',
header: {
'content-type': 'application/json'
},
success: function (res) {
that.setData({
position: res.data
})
console.log('position',that.data.position)
var lengthOfRes = res.data.length;
console.log('len',lengthOfRes)
for(var i=0;i<lengthOfRes;i++){
that.data.positionArr[i]={
latitude:that.data.position[i].latitude,
longitude:that.data.position[i].longitude
}
}
}
})
that.mapLoad();
console.log('long',that.data.longitude)
},
mapLoad: function () {
qqmapsdk = new QQMapWX({
key: '。。。。。。。。。。'
});
this.mapCtx = wx.createMapContext('myMap');
wx.getLocation({
type:'gcj02',
success:(res)=>{
console.log('dingwei',res)
this.setData({
longitude:res.longitude,
latitude:res.latitude
})
}
});
this.drawline();
//隐藏定位中信息进度
wx.hideLoading()
},
drawline:function(){
let that=this;
console.log('su',that.data.positionArr)
let polyline = [{
points: that.data.positionArr,
color: '#00ff00',
width: 5,
}];
that.setData({
polyline: polyline
});
console.log('polyline',that.data.polyline)
}
<map id="map" class="maMap" subkey="。。。。。。。" longitude="{{longitude}}" latitude="{{latitude}}" markers="{{markers}}" polyline="{{polyline}}" show-location>
</map>
你在真机上面看看,地图中有一些配置在开发工具上不会显示,但是在真机上面会正确显示的