How to convert post code to city name, is there an API available?
You need a service that does geocoding.
Yahoo's Geocoder API is getting much better results globally.
110021
is the postal code for New Delhi among several other places in the world.
This seems to get them all.
Google Maps API is another such service but I'm not happy with the geocoded results as I don't get all results back for 110021
.
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': '110021'}, function(results, status) {
console.log(results);
});
Two years later, IMO the Google Maps Geocoding API is the best way to go.
Just pass in the postal code as the address parameter:
http://maps.googleapis.com/maps/api/geocode/json?address=94043&sensor=false
http://zipasaur.us/ is incredible and free. I just discovered it after quite some searching.
It can do reverse lookups like you ask and more. It's free and has a JSON API. Awesome!
[edit] It's down now and has been for quite some time. It was nice while it lasted though :(
The US Post Office sells a subscription to map 5 digit zip codes to City/State values. As @Timothy says, the mapping is one to many. However, the post office db does mark which city/state is the "primary" for a given zip code.
Don't know about other countries. Check with your country's postal authority.
RedLine offers a free zipcode API service (up to 250 requests per hour). There are 4 different varieties covering distances between two zipcodes, zipcodes within a radius of a zipcode, City, state and Lat/long of a zipcode and the zipcode of a city. http://zipcodedistanceapi.redline13.com/
Just to put in my .02, using the Google Maps API mentioned above, you can look up global information. I am currently working on a project and am pretty much implementing it as my solution for this issue. Ok, off my tiny soap box.
来源:https://stackoverflow.com/questions/2846466/how-to-convert-postal-code-to-city-name-is-there-an-api-available