收藏
回答

wx.getSetting() 在用户点击地理位置授权后,打印授权信息undefined?

wx.getLocation({
        type: 'wgs84',
        success(res) {
          //维度
          text["latitude"] = res.latitude
          //经度
          text["longitude"] = res.longitude
          wx.setStorage({
            key: "Location",
            data: text
          })
        },
        complete(res) {
          console.log(res)
          wx.getSetting({
            success: (res) => {
              console.log(res.authSetting)
              console.log(res.authSetting['scope.userLocation'])
              console.log(!res.authSetting['scope.userLocation'])
              if (!res.authSetting['scope.userLocation']){
                wx.showModal({
                  content: '检测到您没打开定位权限,为了活动体验是否去设置打开?',
                  confirmText: "确认",
                  cancelText: "取消",
                  success: function (res) {
                    console.log(res);
                    //点击“确认”时打开设置页面
                    if (res.confirm) {
                      console.log('用户点击确认')
                      wx.openSetting({
                        success: (res) => {
                          console.log(res)
                        }
                      })
                    } else {
                      console.log('用户点击取消')
                    }
                  },
                  complete() {
                    
                  }
                });
              }else{
                
              }
            }
          })
        }
      })

接口先调用wx.getLocation()后调用wx.getSetting()打印位置授权res.authSetting['scope.userLocation'undefined



这是啥情况啊?求解,有时候出来,有时候undefined就很郁闷.

基础库2.8.1   开发者工具 v1.02.1907301


最后一次编辑于  09-19
回答关注问题邀请回答
收藏

1 个回答

  • 浅木
    浅木
    09-19

    你可以这样写的。

    09-19
    赞同
    回复 2
    • 浅木
      浅木
      09-19
      而且你报undefined 主要是你取错了,应该是res.errMsg
      09-19
      回复
    • 。。。。
      。。。。
      09-19

      emmm,确实res.errMsg就可以判断了,但是我还是没太理解,为啥在那里面调用getSetting拿不到那个位置授权信息呢,

      09-19
      回复
问题标签