• 小程序取消地理位置授权后,重新授权


    首次进入该页面,调用wx.getLocation要求用户进行授权;用户拒绝后,再次进入该页面,我们通过wx.getSetting接口,返回用户授权的情况:

    getLocation: function () {
        var that = this;
        //1、获取当前位置坐标
        wx.getLocation({
          type: 'wgs84',
          success: function (res) {
            wx.setStorageSync('latitude', res.latitude);
            wx.setStorageSync('longitude', res.longitude);
          }
        })
      },

    1.展现步骤---取消获取你的地理位置

    2.再次弹出是否授权当前位置弹窗

    3.授权所弹出界面

    again_getLocation:function(){
        let that = this;
        // 获取位置信息
        wx.getSetting({
          success: (res) => {
            console.log(res)
            if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {//非初始化进入该页面,且未授权
              wx.showModal({
                title: '是否授权当前位置',
                content: '需要获取您的地理位置,请确认授权,否则无法获取您所需数据',
                success: function (res) {
                  console.log(res)
                  if (res.cancel) {
                    that.setData({
                      isshowCIty: false
                    })
                    wx.showToast({
                      title: '授权失败',
                      icon: 'success',
                      duration: 1000
                    })
                  } else if (res.confirm) {
                    wx.openSetting({
                      success: function (dataAu) {
                        console.log(dataAu)
                        if (dataAu.authSetting["scope.userLocation"] == true) {
                          wx.showToast({
                            title: '授权成功',
                            icon: 'success',
                            duration: 1000
                          })
                          //再次授权,调用getLocationt的API
                          that.getLocation(that);
                        } else {
                          wx.showToast({
                            title: '授权失败',
                            icon: 'success',
                            duration: 1000
                          })
                        }
                      }
                    })
                  }
                }
              })
            } else if (res.authSetting['scope.userLocation'] == undefined) {//初始化进入
              that.getLocation(that);
            }
            else { //授权后默认加载
              that.getLocation(that);
            }
          }
        })
    
      },
  • 相关阅读:
    【BZOJ5281】Talent Show(分数规划)
    数据库的连接(学习笔记)
    锁(学习笔记)
    事务处理(学习笔记)
    游标(学习笔记)
    PL/SQL基础-异常处理
    通用函数(学习笔记)
    转换函数(学习笔记)
    数据库的备份和恢复(学习笔记学习中)
    分析函数
  • 原文地址:https://www.cnblogs.com/jiayeyuan/p/10540252.html
Copyright © 2020-2023  润新知