摘要
getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json
getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json
关注公众号不走丢:
今天在使用uniapp开发小程序,使用用户地理位置的时候报了个错误:
getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json
去网上看了下资料,有说官方文档上在小程序获取用户位置的时候增加了权限,需要申请才行。
于是看了下官方的文档,果然,自从2022年7月开始,新开发的小程序如果想要获取用户的位置信息需要先申请然后在app.json中配置才能使用。例如wx.getLocation接口 https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.getLocation.html
登录小程序,进入如下页面:https://mp.weixin.qq.com/wxamp/categoryapi/index?token=506484046&lang=zh_CN
开发--> 开发管理--> 接口设置,然后根据你的需要以及你的小程序是否有权限申请来申请对应的接口
【
目前需要配置的接口如下(参考官方文档):
开发者需要在 app.json 中 requiredPrivateInfos 配置项中声明如下的代码:
"requiredPrivateInfos": [ "getFuzzyLocation", "choosePoi", "chooseAddress" ],
另外还需要再app.json中配置如下:
"permission": { "scope.userLocation": { "desc": "你的位置信息将用于小程序位置接口的效果展示" } }
需要注意的是,
1、模糊位置信息(序号1)和精确位置信息(序号2-5)是互斥的,即声明了模糊位置信息就无法声明精确位置信息。若同时声明模糊位置信息和精确位置信息,则在编译代码时出现错误;
2、上面的接口只要用到了,都需要配置上去