解决小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json
报错如下:
"getLocation:fail the api need to be declared in the requiredPrivateInfos fi
解决方案:
一、unipp项目
打开uniapp项目的配置文件manifest.json,选择“源码视图”。
/* 小程序特有相关 */
"mp-weixin": {
"appid": "你的开发者id",
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true
},
"usingComponents": true,
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos": [
"getLocation"
]
},二、原生小程序
打开项目的配置文件app.json。
{
"pages": ["pages/index/index"],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
}
},
"requiredPrivateInfos": [
"getLocation"
]
}requiredPrivateInfos的配置扩展:
表1中模糊位置信息(序号1)和精确位置信息(序号2-5)是互斥的,即声明了模糊位置信息就无法声明精确位置信息。
若同时声明模糊位置信息和精确位置信息,则在编译代码时出现错误;
更多文档,请参考官方文档:地理位置接口新增与相关流程调整


![[钉钉]内网穿透之HTTP穿透](https://static-aliyun-doc.oss-accelerate.aliyuncs.com/assets/img/zh-CN/9904269951/p163821.png)