美文网首页
authorize:fail:require permissio

authorize:fail:require permissio

作者: 没_有_人 | 来源:发表于2019-01-22 18:18 被阅读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里面配置

    相关文章

      网友评论

          本文标题:authorize:fail:require permissio

          本文链接:https://www.haomeiwen.com/subject/rmsrjqtx.html