收藏
回答

小程序真机调试,wx.onLocationChange监听位置不准确,请问有什么解决方法?

在真机调试时,手机放着不动,经纬度也一直在变化,甚至前后偏移距离达到30~40米

getAuth(){
    const that = this;
    wx.getSetting({
        success(res) {
          console.log("get auth success: ", res);
          // 如果没有拿到scope.userLocationBackground授权,提示
          if (!res.authSetting['scope.userLocationBackground']) {
              wx.authorize({
                  scope'scope.userLocationBackground',
                  success() {
                      // 用户已经同意,调用wx.startLocationUpdateBackground
                      wx.startLocationUpdateBackground({
                          success(res) {
                              // 成功开启后台定位, 调用实时位置变更
                              that.openLocaionListener()
                          },
                          fail(err) {
                            console.log("error001", err);
                            that.getLocationWithoutListener();
                          }
                      })
                  },
                  fail(err) {
                    console.log("error002", err);
                    that.getLocationWithoutListener();
                  },
              })
          } else {
              // 已经拿到scope.userLocationBackground授权调用
              wx.startLocationUpdateBackground({
                  success(res) {
                      // 成功开启后台定位,
                      that.openLocaionListener()
                  },
                  fail(err) {
                    console.log("startLocationUpdateBackground fail", err);
                  }
              })
          }
        }
    })
  },

openLocaionListenerfunction(){
    console.log("openLocaionListener");
    wx.onLocationChange(this._locationChangeFn) // 开始监听位置变化
  },
最后一次编辑于  2023-02-08
回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2023-02-09

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2023-02-09
    有用
    回复 3
    • 梁晗
      梁晗
      2023-02-09
      代码片段:https://developers.weixin.qq.com/s/IOFaVTmK7dF4
      操作流程:使用真机调试,选择第二项,发现手机放着不动,位置监听一直在变
      2023-02-09
      回复
    • 向阳つ
      向阳つ
      2023-05-04
      都2023年了,21的bug都还在服了
      2023-05-04
      1
      回复
    • Afu
      Afu
      09-02回复梁晗
      没后续了吗?问题解决了吗?也遇到同样的问题
      09-02
      回复
登录 后发表内容