I need a reliable webserivce which gives corresponding city name by passing zip code. This webservice should work at any time. This webservice will be used in the production also.
-
either USA or entrire world. First preference is for USA – karthik k Jun 03 '11 at 14:37
6 Answers
I found a couple of ways to do this with web based APIs. I think the US Postal Service would be the most accurate, since Zip codes are their thing, but Ziptastic looks much easier.
Using the US Postal Service HTTP/XML API
According to this page on the US Postal Service website which documents their XML based web API, specifically Section 4.0 (page 22) of this PDF document, they have a URL where you can send an XML request containing a 5 digit Zip Code and they will respond with an XML document containing the corresponding City and State.
According to their documentation, here's what you would send:
http://SERVERNAME/ShippingAPITest.dll?API=CityStateLookup&XML=<CityStateLookupRequest%20USERID="xxxxxxx"><ZipCode ID= "0"><Zip5>90210</Zip5></ZipCode></CityStateLookupRequest>
And here's what you would receive back:
<?xml version="1.0"?>
<CityStateLookupResponse>
<ZipCode ID="0">
<Zip5>90210</Zip5>
<City>BEVERLY HILLS</City>
<State>CA</State>
</ZipCode>
</CityStateLookupResponse>
USPS does require that you register with them before you can use the API, but, as far as I could tell, there is no charge for access. By the way, their API has some other features: you can do Address Standardization and Zip Code Lookup, as well as the whole suite of tracking, shipping, labels, etc.
Using the Ziptastic HTTP/JSON API
This is a pretty new service, but according to their documentation, it looks like all you need to do is send a GET request to http://ziptasticapi.com, like so:
GET http://ziptasticapi.com/48867
And they will return a JSON object along the lines of:
{"country": "US", "state": "MI", "city": "OWOSSO"}
Indeed, it works. You can test this from a command line by doing something like:
curl http://ziptasticapi.com/48867

- 663
- 2
- 9
- 22

- 4,760
- 3
- 27
- 34

- 187,200
- 47
- 362
- 445
-
This looks like a really good bet, you just pass in the ZIP code and then it returns the city name, along with latitude and longitude in a JSON string. – CrowderSoup Jun 03 '11 at 13:47
-
-
perhaps http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP would work for you

- 1,686
- 4
- 30
- 38
-
After adding this url as a webreference I am unable to get the methods of the webservice. – karthik k Jun 03 '11 at 14:42
-
1http://www.webservicex.net/uszip.asmx will give you the methods. – Stuart Siegler Jun 08 '11 at 21:03
-
-
Quick note -- that service doesn't currently support CORS (if anyone else is trying to find an ajax solution). – Luke A. Leber Sep 20 '16 at 22:52
-
This service doesnt give for specific zipcodes. Some examples are :89179, 75965, 72019, 33449, 76549, 75803, 97703, 76210, 84005 – Sana Ahmed Mar 14 '17 at 09:59
-
@Sana I think this was a sample service designed for testing web service calls and processing. I don't believe it was meant to be an actual zip code support service, and there are better ones now... – Stuart Siegler Mar 14 '17 at 11:31
-
-
1
The Yahoo PlaceFinder API will work for this type of query.
http://developer.yahoo.com/geo/placefinder/guide/index.html
I believe that
http://where.yahooapis.com/geocode?appid=<appID>&postal=<zipCode>
will get you what you're looking for.

- 3,232
- 2
- 20
- 20
Also http://www.zipwise.com/webservices gives XML and JSON results for free for zip code lookups, radius searches, reverse lookups, and latitude/longitude stuff.

- 389
- 3
- 14
This may suite your need if you want something to obtain city/state information:
http://www.usps.com/webtools/address.htm
Its a API in which you sign up for.

- 27
- 4