腾讯WeMap-微信小程序-报错之getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json

文档:

https://lbs.qq.com/

  wx.getLocation({
    type: 'wgs84',
    success(res) {
      console.log(res)
    },
    fail(res) {
      console.log(res) // getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json
    }
  })

错误场景:在开发者工具中,是可以success的,但是在真机调试的时候,就会fail,原本考虑是,配置问题:

https://lbs.qq.com/faq/miniprogramFaq/wxJsSdk

 

 

 

 

但是查看了微信平台,已经配置过了

 

 

解决方案:

小程序app.json添加:

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

最主要的是红色的部分。

最终问题解决。

 参考:

https://blog.csdn.net/qq_40047019/article/details/125997964

posted @ 2022-09-26 16:52  最爱小虾  阅读(2427)  评论(0编辑  收藏  举报