tscherg
tscherg

Reputation: 1082

Can I force Google geocoding API to include the postcode on geocoding request?

I am using Google Geocoding API to get lat, lng, country and postal_code from any address string.

In certain situations I noticed a problem where in my opinion the API is wasteful with requests. Is there a way to work around it or even an intended solution that I don't see?

Upvotes: 1

Views: 1536

Answers (1)

xomena
xomena

Reputation: 32198

In example that you provided, request https://maps.googleapis.com/maps/api/geocode/json?address=New%20York%2C%20USA&key=YOUR_API_KEY returns a feature of type locality (place ID ChIJOwg_06VPwokRYv534QaPC8g).

Note that this feature refers to entire city, not to the position of the center of the city.

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DNew%2520York%252C%2520USA

As locality is not a single point (it has a polygon shape) and the feature of locality overlaps many features of postal codes, Google doesn't return any value for postal code due to ambiguity. Unfortunately, you cannot change this behavior. The only workaround as you mentioned is reverse geocode a postal code of the central point.

I hope my answer clears up your doubt.

Upvotes: 1

Related Questions