收藏
回答

地图marker方向角不动

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug map 微信iOS客户端 7.0.13 2.12.0

将手机竖起来初始化角度是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++

    }

  },




回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签