微信小程序中用户拒绝授权的处理方式

微信小程序中用户拒绝授权的处理方式
首先,1.获取经纬度 wx.getLocation来获取地址
2.拒绝后, wx.getSetting来判断用户拒绝
3.wx.openSetting来引导用户打开地址允许
4.再次获取地址即可

// 获取经纬度地址
    wx.getLocation({
      type: 'gcj02',
      altitude: true,
      isHighAccuracy: true,
      success(res) {
        // console.log(res) 这里可以获取到经纬度
        wx.request({
          url: getAddressUrl,
          success: function (result) {
            // console.log(result)
            // console.log(result.data.result.formatted_addresses.recommend)
            that.globalData.userInfo.address = result.data.result.formatted_addresses.recommend
          }
        })
      },
      fail: function (e) {
      	//这里是获取失败的时候
        // console.log(e)
        wx.getSetting({
          success: res => {
            if (typeof (res.authSetting['scope.userLocation']) != 'undefined' && !res.authSetting['scope.userLocation']) {
              // 用户拒绝了授权
              wx.showModal({
                title: '提示',
                content: '您拒绝了定位权限,将无法使用XX功能',
                success: res => {
                  if (res.confirm) {
                  //打开设置 让用户点击允许 这样可以重新获取
                    wx.openSetting({
                      success: res => {
                        if (res.authSetting['scope.userLocation']) {
                          // 授权成功,重新定位即可
                          wx.getLocation({
                            type: 'gcj02',
                            altitude: true,
                            isHighAccuracy: true,
                            success: res => {
                             
                            },
                            fail: err => {
                              console.log(err)
                            }
                          });
                        } else {
                          // 没有允许定位权限
                          wx.showToast({
                            title: '没有允许定位权限',
                            icon: 'none'
                          });
                        }
                      }
                    });
                  }
                }
              });
            }
          }
        });

      }
    })
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值