一,getlocation时报错:
代码:<template> <view> <button style="width:710rpx;height:80rpx;" @click="openMap">打开地图</button> </view> </template> <script> export default { data() { return { } }, methods: { openMap(){ uni.getLocation({ success: res => { console.log('location success', res) uni.openLocation({ latitude: res.latitude, longitude: res.longitude, scale: 18 }) }, fail:res=>{ console.log('location fail', res) } }); }, } } </script> <style> </style>报错:
getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json如图:
![](/i/l/?n=23&i=blog/1938691/202302/1938691-20230224142259643-1739082101.png)
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: [email protected]
二,解决:
编辑manifest.json 增加一行:"requiredPrivateInfos": ["getLocation", "chooseLocation"]如图:
![](/i/l/?n=23&i=blog/1938691/202302/1938691-20230224142259711-611151573.png)
三,测试效果:
![](/i/l/?n=23&i=blog/1938691/202302/1938691-20230224142259876-2000827920.png)
三,查看hbuilderx的版本:
![](/i/l/?n=23&i=blog/1938691/202302/1938691-20230224142225914-1929024108.png)
标签:getlocation,微信,app,json,res,fail,uni,com From: https://www.cnblogs.com/architectforest/p/17151350.html