{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 日前发布的小程序不受影响。

申明需要使用的地理位置相关接口,类型为数组。目前支持以下项目:

如:

{ "pages": ["pages/index/index"], "requiredPrivateInfos": [ "getLocation", "onLocationChange", "startLocationUpdateBackground" "chooseAddress" ] } 

注:若使用以上接口,均需在小程序管理后台,「开发」-「开发管理」-「接口设置」中自助开通该接口权限。



添加获取地理位置的代码授权

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

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部