Google Places API returns "Unsupported field name 'address_component'"

Viewed 682

I'm using the Google Places API to find the address details of a small village in India, following this documentation from Google. My https request looks as follows:

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

My problem is that the request above returns the following error:

Error while parsing 'fields' parameter: Unsupported field name 'address_component'.

I've tried a couple of other 'field' values, and they all seem to work except for address_component. Any thoughts on what I'm doing wrong?

2 Answers

Figured this one out. Apparently "Place Search, Nearby Search, and Text Search requests all return a subset of the fields that are returned by Place Details requests." See here for details: LINK

address_component is one of the fields that is not supported ...

I went through the same thing a while ago, basically you should make 2 calls, the first one to:

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

this will return the following.

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

you should take the place_id and use it in a second call like this:

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

this will return the following.

{
    "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"
}

I don't know why the other way in the documentation, I imagine that at some point due to billing issues they have separated it into 2 calls.

From what I understood about billing, for every 1000 addresses searched in this way, you would be spending approximately 34 USD.

Related