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

2024-04-25

我正在使用 Google Places API 查找印度一个小村庄的地址详细信息,如下所示文档 https://developers.google.com/maps/documentation/places/web-service/search-find-place#fields来自谷歌。我的 https 请求如下所示:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?key=MY_API_KEY&inputtype=textquery&input=Dahigaon&fields=name,geometry,address_component

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

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

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


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

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

这将返回以下内容。

{
    "candidates": [
        {
            "place_id": "ChIJCesBrxmd5ogR5kyZiY35HLI"
        }
    ],
    "status": "OK"
}

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

curl --request GET \
  --url 'https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJCesBrxmd5ogR5kyZiY35HLI&key=YOUR_KEY'

这将返回以下内容。

{
    "html_attributions": [],
    "result": {
        "address_components": [
            {
                "long_name": "360",
                "short_name": "360",
                "types": [
                    "street_number"
                ]
            },
            {
                "long_name": "Lobelia Road",
                "short_name": "Lobelia Rd",
                "types": [
                    "route"
                ]
            },
            {
                "long_name": "St. Augustine",
                "short_name": "St. Augustine",
                "types": [
                    "locality",
                    "political"
                ]
            },
            {
                "long_name": "St. Johns County",
                "short_name": "St Johns County",
                "types": [
                    "administrative_area_level_2",
                    "political"
                ]
            },
            {
                "long_name": "Florida",
                "short_name": "FL",
                "types": [
                    "administrative_area_level_1",
                    "political"
                ]
            },
            {
                "long_name": "United States",
                "short_name": "US",
                "types": [
                    "country",
                    "political"
                ]
            },
            {
                "long_name": "32086",
                "short_name": "32086",
                "types": [
                    "postal_code"
                ]
            },
            {
                "long_name": "6516",
                "short_name": "6516",
                "types": [
                    "postal_code_suffix"
                ]
            }
        ],
        "adr_address": "<span class=\"street-address\">360 Lobelia Rd</span>, <span class=\"locality\">St. Augustine</span>, <span class=\"region\">FL</span> <span class=\"postal-code\">32086-6516</span>, <span class=\"country-name\">USA</span>",
        "formatted_address": "360 Lobelia Rd, St. Augustine, FL 32086, USA",
        "geometry": {
            "location": {
                "lat": 29.8358907,
                "lng": -81.31464799999999
            },
            "viewport": {
                "northeast": {
                    "lat": 29.8372717802915,
                    "lng": -81.31318596970848
                },
                "southwest": {
                    "lat": 29.8345738197085,
                    "lng": -81.31588393029149
                }
            }
        },
        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png",
        "icon_background_color": "#7B9EB0",
        "icon_mask_base_uri": "https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet",
        "name": "360 Lobelia Rd",
        "place_id": "ChIJCesBrxmd5ogR5kyZiY35HLI",
        "reference": "ChIJCesBrxmd5ogR5kyZiY35HLI",
        "types": [
            "premise"
        ],
        "url": "https://maps.google.com/?q=360+Lobelia+Rd,+St.+Augustine,+FL+32086,+USA&ftid=0x88e69d19af01eb09:0xb21cf98d89994ce6",
        "utc_offset": -240,
        "vicinity": "St. Augustine"
    },
    "status": "OK"
}

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐