将手机竖起来初始化角度是0时,update marker后角度不变,update参数有值
onCompassChange: function(){// 方向监听
wx.onCompassChange((res)=> {
if(preDirection && (Math.abs(res.direction - preDirection) < 10)) {
return false
}
preDirection = res.direction;
this.setData({direc: preDirection})
console.log(‘更新方向’,preDirection)
// 定位点方向更新
this.updateMaker({
markerId: 1,
rotate: preDirection
})
});
},
updateMaker: function(e){ //更新定位点信息
// 更新图标定位点
let _markers = this.data.markers;
let idx = 0
for(let item of _markers) {
if (item.id == e.markerId) {
if(e.destination) {
item.latitude = e.destination.latitude;
item.longitude = e.destination.longitude;
}
if (e.rotate || e.rotate === 0) item.rotate = e.rotate;
if (e.buildingId) {
item.buildingId = e.buildingId;
} else {
delete item.buildingId
}
if (e.buildingId) {
item.floorName = e.floorName;
} else {
delete item.floorName
}
this.setData({
[`markers[${idx}]`]: item
})
if (e.rotate || e.rotate === 0){
console.log(‘更新方向后的结果 ,’, item) //此处能打印出角度 经纬度生效了,但是角度不动
}
break
}
idx++
}
},
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)