{errMsg: "getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json"}
出现这个是什么原因
报错信息是errMsg: "getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json"
打开manifest.json的源码视图
官方说明
https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#permission
requiredPrivateInfos
自 2022 年 7 月 14 日后发布的小程序,使用以下8个地理位置相关接口时,需要声明该字段,否则将无法正常使用。2022 年 7 月 14 日前发布的小程序不受影响。
申明需要使用的地理位置相关接口,类型为数组。目前支持以下项目:
- getFuzzyLocation: 获取模糊地理位置
- getLocation: 获取精确地理位置
- onLocationChange: 监听实时地理位置变化事件
- startLocationUpdate: 接收位置消息(前台)
- startLocationUpdateBackground: 接收位置消息(前后台)
- chooseLocation: 打开地图选择位置
- choosePoi: 打开POI列表选择位置
- chooseAddress: 获取用户地址信息
如:
{ "pages": ["pages/index/index"], "requiredPrivateInfos": [ "getLocation", "onLocationChange", "startLocationUpdateBackground" "chooseAddress" ] }
注:若使用以上接口,均需在小程序管理后台,「开发」-「开发管理」-「接口设置」中自助开通该接口权限。
添加获取地理位置的代码授权
"mp-weixin" : {
"permission" : {
"scope.userLocation" : {
"desc" : "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos" : [ "getLocation", "chooseLocation" ]
},
发表评论 取消回复