0
点赞
收藏
分享

微信扫一扫

用户拒绝授权定位信息的

Gascognya 2022-03-26 阅读 69
小程序

在使用wx.getLocation请求位置时,一旦用户明确同意或拒绝过授权,其授权关系会记录在后台,直到用户主动删除小程序,

如果用授权后,可以通过调用wx.openSetting,打开设置页。

<view class="img-box">
      <image wx:if="{{QrCode}}" src="{{QrCode}}" bindtap="getRefresh" style="width: 100%;height: 100%;"></image>
      <view wx:else class="img-box-text" >
         <text>{{ResultMsg}}</text>
         <view bindtap="getRefresh">重新获取</view>
      </view>
    </view>
  //获取位置
  locationFunc(){
    var that = this
    wx.getLocation({
      type: 'wgs84',
      success (res) {
        console.log('位置',res)
        that.setData({
          longitude: res.longitude,
          latitude: res.latitude
        })
        //请求接口
        that.GetMemberCodeV2()
      },
      fail(err) {
        console.log(err)
         // 第一次拒绝后,下次点击提示打开设置授权弹窗
        wx.showModal({
          title:'定位获取失败',
          content:'会员码将无法生成,是否去设置授权打开?',
          success(res){
            if (res.confirm) {
              wx.openSetting({
                success: (res) => { 
                  console.log(res,"授权打开定位信息")
                }
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
              that.setData({
                ResultMsg:'定位不成功,会员码获取失败'
              })
            }
          }
        })
      }
      })
  },
举报

相关推荐

0 条评论