小程序获取地理位置第二次授权

时间:2024-04-13 07:27:11

小程序的获取地理位置的授权,先做配置处理(app.json)
“permission”: {
“scope.userLocation”: {
“desc”: “你的位置信息将用于接口的效果展示”
}
},
如果第一次拒绝获取位置后,短时间内不能再弹出授权弹框需要做特殊处理(模拟弹框 其实是showToast)
小程序获取地理位置第二次授权
小程序获取地理位置第二次授权
上图点击确定后做授权判断 ,跳到设置那里打开使用地理位置权限
againGet: function() {
var _this = this;
wx.getSetting({
success: function(res) {
if (res.authSetting[‘scope.userLocation’] != undefined && res.authSetting[‘scope.userLocation’] != true) {
wx.showModal({
title: ‘请求授权当前位置’,
content: ‘需要获取您的地理位置,确认授权?’,
success: function(res) {
if (res.confirm) {
wx.openSetting({
success: function(res) {
if (res.authSetting[“scope.userLocation”] == true) {
}
}
})
}
}
})
}
},
fail: function(res) {}
})
},
小程序获取地理位置第二次授权