小程序
小游戏
企业微信
微信支付
扫描小程序码分享
公众号网页h5,h5中使用微信js-sdk里的获取地理位置接口wx.getLocation,拒绝了授权怎么再调起呢?
4 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
请问解决了吗 我也遇到这个问题了 ,礼貌求解~
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
在代码里判断,如果用户拒绝,然后再拒绝后重新要求再次授权,直到客户点击允许
wx.getSetting({
success: (res) => {
console.log(JSON.stringify(res))
// res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
// res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
// res.authSetting['scope.userLocation'] == true 表示 地理位置授权
if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
wx.showModal({
title: '请求授权当前位置',
content: '需要获取您的地理位置,请确认授权',
success: function (res) {
if (res.cancel) {
wx.showToast({
title: '拒绝授权',
icon: 'none',
duration: 1000
})
} else if (res.confirm) {
wx.openSetting({
success: function (dataAu) {
if (dataAu.authSetting["scope.userLocation"] == true) {
title: '授权成功',
icon: 'success',
//再次授权,调用wx.getLocation的API
self.getLocation();
} else {
title: '授权失败',
}
} else if (res.authSetting['scope.userLocation'] == undefined) {
//调用wx.getLocation的API
用户手动拒绝了就没办法了,只能引导去手动打开
本回答由AI生成,可能已过期、失效或不适用于当前情形,请谨慎参考
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
请问解决了吗 我也遇到这个问题了 ,礼貌求解~
在代码里判断,如果用户拒绝,然后再拒绝后重新要求再次授权,直到客户点击允许
wx.getSetting({
success: (res) => {
console.log(JSON.stringify(res))
// res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
// res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
// res.authSetting['scope.userLocation'] == true 表示 地理位置授权
if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
wx.showModal({
title: '请求授权当前位置',
content: '需要获取您的地理位置,请确认授权',
success: function (res) {
if (res.cancel) {
wx.showToast({
title: '拒绝授权',
icon: 'none',
duration: 1000
})
} else if (res.confirm) {
wx.openSetting({
success: function (dataAu) {
if (dataAu.authSetting["scope.userLocation"] == true) {
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
})
//再次授权,调用wx.getLocation的API
self.getLocation();
} else {
wx.showToast({
title: '授权失败',
icon: 'none',
duration: 1000
})
}
}
})
}
}
})
} else if (res.authSetting['scope.userLocation'] == undefined) {
//调用wx.getLocation的API
} else {
//调用wx.getLocation的API
}
}
})
用户手动拒绝了就没办法了,只能引导去手动打开