Webservice to get City Names by giving Zip Codes
Solution 1
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
Solution 2
http://www.geonames.org/postal-codes/
has it for multiple countries
Solution 3
perhaps http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP would work for you
Solution 4
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.
Solution 5
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.
karthik k
Updated on September 20, 2020Comments
-
karthik k over 3 years
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.
-
CrowderSoup almost 13 yearsThis 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.
-
karthik k almost 13 yearsGetting error while adding this URL as a web reference
-
Daniel A. White almost 13 years
-
karthik k almost 13 yearsAfter adding this url as a webreference I am unable to get the methods of the webservice.
-
Stuart Siegler almost 13 yearswebservicex.net/uszip.asmx will give you the methods.
-
MethodMan about 12 yearsThanks again Stuart actually +2
-
Paul Chernoch over 11 yearsVery simple API. Thanks.
-
Luke A. Leber over 7 yearsQuick note -- that service doesn't currently support CORS (if anyone else is trying to find an ajax solution).
-
Sana Ahmed about 7 yearsThis service doesnt give for specific zipcodes. Some examples are :89179, 75965, 72019, 33449, 76549, 75803, 97703, 76210, 84005
-
Stuart Siegler about 7 years@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...
-
Sana Ahmed about 7 years@StuartSiegler Can you specify some ?
-
Stuart Siegler about 7 years@Sana, zipwise is free: zipwise.com/webservices