onShow: function() {
wx.authorize({
scope: 'scope.userFuzzyLocation',
success(res) {
// console.log(res)
if(res.errMsg == 'authorize:ok'){
wx.getFuzzyLocation({
type: 'wgs84',
success(res) {
console.log(res) //此时里面有经纬度
}
})
}
},
fail(err) {
console.log(err)
}
})
},
app.json
"requiredPrivateInfos": [
"getFuzzyLocation"
],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
}
}
请问为什么? 返回不到数据?
在你的 app.json 文件中,你已经定义了对用户位置信息的获取授权,但是你的代码中似乎并没有申请该权限。可以通过 wx.authorize 方法来获取该权限:
wx.authorize({
scope: 'scope.userLocation',
success() {
// 成功获取授权,可以执行相应操作
},
fail() {
// 获取授权失败,需要用户手动开启授权
}
})
检查代码后发现没有bug,解决方案:
1、将需要的定位权限加入到项目中,在app.json中添加如下代码:
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
}
},
2、重新发布小程序,就可以获取到定位了。
以上回答来自ChatGPT