
1:微信小程序中,目前版本无法自动直接弹窗,使用位置授权需搭配 uni.getSetting
2:在manifest.json配置文件中勾选:微信小程序设置->位置接口描述

3:在app.vue onLaunch()中添加如下代码或定义外部方法调用
uni.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
// 未授权
uni.authorize({
scope: 'scope.userLocation',
success() { //1.1 允许授权
uni.getLocation()
},
fail(){ //1.2 拒绝授权
console.log("你拒绝了授权,无法获得周边信息")
}
})
}else{
// 已授权 ..(获取位置信息)
}
}
});
网友评论