使用uniapp开发小程序getLocation报错

发布时间 2023-11-06 14:46:23作者: rht

uniapp中使用uni.getLocation()报错,报错如下:

getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json

 首先检查uniapp的manifest文件发现位置权限已经开启:

 后翻阅微信文档后发现原来是微信官方做了调整,uniapp只勾选这个还不行,调整链接:地理位置接口新增与相关流程调整 | 微信开放社区 (qq.com)
打开manifest文件找到mp-weixin加入

"requiredPrivateInfos": ["getLocation"]

就ok了;

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