uniapp调用微信小程序调用百度地图,发现定位失败。报错如下:
"getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json"
这是因为微信最近标准,定位需要在json文件中标注使用,废话不多说贴代码。
找到mainfest.json ,点击源码试图
找到这块代码:
在下面添加代码如下:
"mp-weixin": {
"appid": "你的开发者id",
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true
},
"usingComponents": true,
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos": [
"getLocation"
]
},
这样就完美解决了定位问题了啦。 有时候微信会更新,所以有时候发现一年前代码没错,现在代码就有错了。