Dinesh Gurrapu
Dinesh Gurrapu

Reputation: 158

How to get exact City name using postal code? I am using the below API but it is not giving exact city name , It is giving only District name

This is the API that I am Using but It is giving only District name and State Name only not giving the name as per postal code. is there any another API to get exact City name. Kindly help me out from this issue.

http://maps.googleapis.com/maps/api/geocode/json?address=&components=postal_code:506366&sensor=false"

Upvotes: 1

Views: 1381

Answers (2)

miguev
miguev

Reputation: 4840

A bit of a tricky one: postcode_localities is only present when the result is a postal code that contains multiple localities. However, 506366 (India) only overlaps with those localities, it does not contain any of them. That's why you won't have a locality in the address.

At the same time, there is no postal code that fully contains those locality, so you won't get a postal_code in their addresses either:

https://maps.googleapis.com/maps/api/geocode/json?&address=Parlapalle%20506366%20india https://maps.googleapis.com/maps/api/geocode/json?&address=Akinepalle%20506366%20india

Here's an example where postcode_localities is returned: 13100 (France): https://maps.googleapis.com/maps/api/geocode/json?components=country%3AFR%7Apostal_code%3A13100

Upvotes: 1

xomena
xomena

Reputation: 32100

Looking at the postal code boundaries on maps.google.com it seems that the postal code overlaps several localities:

https://www.google.es/maps/place/Telangana+506366,+India/@18.3178586,79.5682081,12.25z/data=!4m5!3m4!1s0x3a3324c84ccde691:0xdedd70d16ab9cfab!8m2!3d18.3214924!4d79.616521

In such situation Geocoding API doesn't return a locality in address component because of ambiguity.

However, I would expect the postcode_localities array in the response that according to the documentation

is an array denoting all the localities contained in a postal code. This is only present when the result is a postal code that contains multiple localities.

https://developers.google.com/maps/documentation/geocoding/intro#Results

At this point it looks like a bug. I can suggest raising an issue in the public issue tracker: https://code.google.com/p/gmaps-api-issues/

Upvotes: 1

Related Questions