Search code examples
google-mapsgoogle-apigoogle-geocoder

Cannot get Sicily (as region) from maps.googleapis.com


How can I use google API to exclude the establishment/natural_feature from the results?

For example, I cannot get Sicily as region.

This is the URL http://maps.googleapis.com/maps/api/geocode/json?address=Sicily,+Italy&components=administrative_area

Whatever I try to put on 'address' parameter, always I get the Sicily as establishment/natural_feature, and not as region.

The Sicily exists as region with place_id 'ChIJs1lT0GhiEBMRUH22ZykECwE', but I cannot reach it through search.

Sicily region: https://maps.googleapis.com/maps/api/place/details/json?key=API_KEY&placeid=ChIJs1lT0GhiEBMRUH22ZykECwE


Solution

  • If your application supposes the interaction with user, the place autocomplete should help. This is recommended approach in the best practices document.

    Otherwise I'm afraid you cannot specify a type of result in forward geocoder. It will return the feature that is considered the most prominent. Apparently, the natural feature (island) is considered more prominent than a region in this example. The unique workaround I can think of is applying reverse geocoding for coordinates from the first request and set a result type to administrative area level 1.

    https://maps.googleapis.com/maps/api/geocode/json?latlng=37.3979297%2C14.6587821&result_type=administrative_area_level_1&key=YOUR_API_KEY