1、微信小程序中,目前版本無法自動直接彈窗,使用位置授權需搭配 uni.getSetting
2、在app.vue onLaunch()中添加如下代碼或定義外部方法調用
1 uni.getSetting({ 2 success(res) { 3 if (!res.authSetting['scope.userLocation']) { 4 // 未授權 5 uni.authorize({ 6 scope: 'scope.userLocation', 7 success() { //1.1 允許授權 8 uni.getLocation() 9 10 }, 11 fail(){ //1.2 拒絕授權 12 console.log("你拒絕了授權,無法獲得周邊信息") 13 } 14 }) 15 }else{ 16 // 已授權 ..(獲取位置信息) 17 } 18 } 19 });
3、在manifest.json配置文件中勾選:微信小程序設置->位置接口描述
其他完整代碼參考:https://blog.csdn.net/qq_42231156/article/details/89764301