Question

is there any server available that i can use for getting zip codes on the basis on city/state ?

Thanks

Was it helpful?

Solution

You can use geonames postal code search. For example:

http://ws.geonames.org/postalCodeSearch?adminCode1=CA&placename=San+Francisco&maxRows=3

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<totalResultsCount>76</totalResultsCount>
<code>
<postalcode>94102</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.781334</lat>
<lng>-122.416728</lng>
<adminCode1>CA</adminCode1>

<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94103</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.77254</lat>

<lng>-122.414664</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94107</postalcode>
<name>San Francisco</name>

<countryCode>US</countryCode>
<lat>37.762147</lat>
<lng>-122.397099</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>

</code>
</geonames>

OTHER TIPS

You can use 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 3.0 (page 13) of this PDF document, they have a URL where you can send an XML request containing an address minus the Zip Code and they will respond with an XML document containing the complete address.

You can't do a lookup with just a city and state though, because a single city can contain multiple ZIP codes, so you need to pass the street address as well.

According to their documentation, this is what your request would look like:

GET http://SERVERNAME/ShippingAPITest.dll?API=ZipCodeLookup&XML=<ZipCodeLookupRequest%20USERID="xxxxxxx"><Address ID="0"><Address1></Address1> <Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>

And here's what you would receive back:

<?xml version="1.0"?> 
<ZipCodeLookupResponse> 
    <Address ID="0"> 
        <Address2>6406 IVY LN</Address2> 
        <City>GREENBELT</City> 
        <State>MD</State> 
        <Zip5>20770</Zip5> 
        <Zip4>1441</Zip4> 
    </Address> 
</ZipCodeLookupResponse>

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top