ankit sharma
ankit sharma

Reputation: 449

Administrative Area Level 2 missing in some places results

I am not getting county('administrative_area_level_2') for some of places, one of them is :

formatted_address: "Barangaroo NSW 2000, Australia" place_id: "ChIJ1ZL9NkGuEmsRUEkzFmh9AQU"

Can anyone help, how to get county ?

Thanks

Upvotes: 1

Views: 2737

Answers (1)

xomena
xomena

Reputation: 32158

The Geocoding API and Places API web services return in the response only address components that are relevant for address formatting of the given feature. In your example the place ID ChIJ1ZL9NkGuEmsRUEkzFmh9AQU doesn't need the administrative area level 2 to create formatted address Barangaroo NSW 2000, Australia, so this address component is missing in the response.

The workaround is the following. Use latitude, longitude of the Barangaroo NSW 2000, Australia (-33.86379410000001,151.2022304) and execute reverse geocoding with result type equal to administrative area level 2.

https://maps.googleapis.com/maps/api/geocode/json?latlng=-33.86379410000001%2C151.2022304&result_type=administrative_area_level_2&key=YOUR_API_KEY

This request returns the

 "address_components":[
    {
      "long_name":"Council of the City of Sydney",
      "short_name":"Sydney",
      "types":[
        "administrative_area_level_2","political"
      ]
    },
    {
      "long_name":"New South Wales",
      "short_name":"NSW",
      "types":[
        "administrative_area_level_1","political"
      ]
    },
    {
      "long_name":"Australia",
      "short_name":"AU",
      "types":[
        "country","political"
      ]
    }
  ]

I hope this helps!

Upvotes: 4

Related Questions