uni.authorize({
scope: "scope.userLocation",
success() {
uni.getLocation({
isHighAccuracy: true, //开启高精度定位
success(res) {
console.log(res)
},
fail(err) {
console.log(err);
console.log("出错了")
}
})
}
})
authorize是声明权限,询问用户是否开启定位权限,然后要进行微信小程序配置,否则会报错
"mp-weixin": {
"appid": "wx3781e15bf6cd4732",
"setting": {
"urlCheck": false
},
"usingComponents": true,
"permission": { //就是弹出的询问是否授权的弹窗
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
}
},
"requiredPrivateInfos": [ //配置要使用的api
"getLocation"
]
},