微信小程序在使用wx.getLocation控制台报错:getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json

原因 在小程序的 app.json 或者 ext.json 文件中,有一个 requiredPrivateInfos 字段用于声明需要使用的私有接口。这些私有接口需要在此字段中进行声明。

解决方案:

在manifest.json,源码视图,mp-weixin里插入一下代码:

JavaScript Code复制内容到剪贴板

  1. "requiredPrivateInfos":["getLocation"],