Handling Location Permission Rejection and Subsequent Authorization in Mini Programs

When a user first accesses a page, the application calls wx.getLocation to request locatoin permissions. If the user denies the request, subesquent visits can check the current authorization status using wx.getSetting.

getLocation: function () {
  var that = this;
  wx.getLocation({
    type: 'wgs84',
    success: function (res) {
      wx.setStorageSync('latitude', res.latitude);
      wx.setStorageSync('longitude', res.longitude);
    }
  })
}

The process involves three key steps:

  1. Initial permission denial
  2. A prompt appears requestnig location access
  3. Successful authorization confirmation
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: 'Location Access Required',
          content: 'Access to your location is necessary to provide relevant data.',
          success: function (res) {
            if (res.cancel) {
              that.setData({
                isshowCIty: false
              })
              wx.showToast({
                title: 'Authorization Denied',
                icon: 'success',
                duration: 1000
              })
            } else if (res.confirm) {
              wx.openSetting({
                success: function (dataAu) {
                  if (dataAu.authSetting["scope.userLocation"] == true) {
                    wx.showToast({
                      title: 'Authorization Granted',
                      icon: 'success',
                      duration: 1000
                    })
                    that.getLocation(that);
                  } else {
                    wx.showToast({
                      title: 'Authorization Failed',
                      icon: 'success',
                      duration: 1000
                    })
                  }
                }
              })
            }
          }
        })
      } else if (res.authSetting['scope.userLocation'] == undefined) {
        that.getLocation(that);
      } else {
        that.getLocation(that);
      }
    }
  })
}

Tags: mini-program location-permission Authorization wx-getsetting wx-opensetting

Posted on Thu, 14 May 2026 21:19:01 +0000 by davo666