使用uniapp开发小程序getLocation报错
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"] },
然后补充一个错误:uniapp Uncaught TypeError: Cannot read property "'getExtension'" of null

这个错误就比较玄学了,网上看了一下都说重启一下电脑就ok了,我一开始还不相信,最后我还是重启了,发现还真可以,搞不懂;

浙公网安备 33010602011771号