Question

Are there any good webservices out there that provide good lookup information for Countries and States/Provinces?

If so what ones do you use?

Was it helpful?

Solution

If you only need US information, the US Postal Service provides a set of web services it calls WebTools for this exact thing. https://www.usps.com/business/web-tools-apis/welcome.htm. You will need to register to be able to use them but once you're registered they are really simple to use. You just send an XML request over HTTP and the server sends an XML response back and you just have to unpack it.

Sample request:

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

Sample response:

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

Here's a link to the technical documentation: https://www.usps.com/business/web-tools-apis/documentation-updates.htm

OTHER TIPS

http://www.geonames.org/

That's the best one I've found. They let you download and host the web service yourself, which is also nice.

A services that works well with .Net (because it leverages WSDL) is http://www.webservicex.net. They have a service for US ZIP codes available at http://www.webservicex.net/uszip.asmx. You can just add it as a service and Visual Studio will take care of the rest. The response comes as an XML response, so you'll have to parse it, but you can use something simple like USZIP.GetInfoByZIP(ZIP).SelectSingleNode("//STATE").InnerText.

For my application I then built an in-memory cache of the data using XML following these directions: http://www.15seconds.com/issue/010410.htm. I used XML instead of a HashTable or Dictionary(TKey, TValue) because I wanted to be able to serialize it to a string so I could save the 'database' as a user setting.

A good source of geographic data, including lookups and mapping data for the USA is the US Census Bureau's TIGER Data set. They no longer actively track Zip code data, but they do have a 1999 vintage file still available.

For countries, the ISO country code list is publicly available.

I'm not aware of resources for information outside the US.

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