10

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.

karthik k
  • 3,751
  • 15
  • 54
  • 68

6 Answers6

12

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 
Benjamin Bakhshi
  • 663
  • 2
  • 9
  • 22
Richard Jones
  • 4,760
  • 3
  • 27
  • 34
5

http://www.geonames.org/

http://www.geonames.org/postal-codes/

has it for multiple countries

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
2

perhaps http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP would work for you

Stuart Siegler
  • 1,686
  • 4
  • 30
  • 38
2

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.

Tom Hazel
  • 3,232
  • 2
  • 20
  • 20
1

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.

CaymanCarver
  • 389
  • 3
  • 14
0

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.

Solaris
  • 27
  • 4