解决微信小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json


报错如下:
UNI-APP_getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json-小白菜博客
解决方案:

unipp项目
打开uniapp项目的配置文件manifest.json,选择“源码视图”。
在这里插入图片描述

"permission" : {
	"scope.userLocation" : {
		"desc" : "你的位置信息将用于小程序位置接口的效果展示"
	}
},
"requiredPrivateInfos": ["getLocation", "chooseLocation"]

原生小程序
打开项目的配置文件app.json。

{
    "pages": ["pages/index/index"],
    "permission": {
        "scope.userLocation": {
            "desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
        }
    },
    "requiredPrivateInfos": ["getLocation", "chooseLocation"]
}