authorize:fail:require permissio

2019-01-22  本文已影响0人  没_有_人

小程序调用wx.chooseLocation接口的时候,获取权限的时候报authorize:fail:require permission desc这样子的错误。
代码如下:

  chooseLocation:function(){
    let _this = this;
    wx.chooseLocation({
      success(e){
        _this.setData({
          map: e.longitude + ',' + e.latitude,
          addr: e.address
        })
      },
      fail(e){
        wx.showToast({
          title: e.errMsg,
          icon:'none'
        })
      }
    })
  },
  getLocation:function(){
    let _this = this;
    wx.getSetting({
      success(res) {
        // 判断定位的授权
        if (!res.authSetting['scope.userLocation']) {
          wx.authorize({
            scope: 'scope.userLocation',
            success() {
              _this.chooseLocation();
            },
            fail(errMsg) {
              wx.showToast({ title: JSON.stringify(errMsg), icon: 'none' }) 
            }
          })
        } else {
          _this.chooseLocation();
        }
      }
    })
  },

代码我检查了很多遍,没有发现什么问题,后来查看文档,发现了原因。


image.png

如果要用到wx.chooseLocation接口的时候要在app.json里面配置

上一篇 下一篇

猜你喜欢

热点阅读