Google Places API 返回“不支持的字段名称‘address_component’”

MRR*_*MRR 10 google-maps google-places-api

我正在使用 Google Places API 遵循Google 的文档查找印度一个小村庄的地址详细信息。我的 https 请求如下所示:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?key=MY_API_KEY&inputtype=textquery&input=Dahigaon&fields=name,geometry,address_component
Run Code Online (Sandbox Code Playgroud)

我的问题是上面的请求返回以下错误:

解析“fields”参数时出错:不支持的字段名称“address_component”。

我尝试了其他几个“字段”值,除了 address_component 之外,它们似乎都有效。对我做错了什么有什么想法吗?

MRR*_*MRR 10

想通了这一点。显然,“地点搜索、附近搜索和文本搜索请求都返回地点详细信息请求返回的字段的子集。” 详细信息请参见此处:链接

地址组件是不支持的字段之一......


小智 10

我不久前也经历过同样的事情,基本上你应该打两个电话,第一个电话:

curl --request GET \
  --url 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=360%20Lobelia%20Rd&inputtype=textquery&key=YOUR_KEY'
Run Code Online (Sandbox Code Playgroud)

这将返回以下内容。

curl --request GET \
  --url 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=360%20Lobelia%20Rd&inputtype=textquery&key=YOUR_KEY'
Run Code Online (Sandbox Code Playgroud)

您应该获取 place_id 并在第二次调用中使用它,如下所示:

curl --request GET \
  --url 'https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJCesBrxmd5ogR5kyZiY35HLI&key=YOUR_KEY'
Run Code Online (Sandbox Code Playgroud)

这将返回以下内容。

{
    "candidates": [
        {
            "place_id": "ChIJCesBrxmd5ogR5kyZiY35HLI"
        }
    ],
    "status": "OK"
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么文档中的另一种方式,我想在某些时候由于计费问题,他们将其分为两个调用。

根据我对计费的理解,以这种方式每搜索 1000 个地址,您将花费大约 34 美元。