US Zip Codes Database

More and more, businesses have “store locators” on their web sites.  Most of them want either a State and City, or a Zip Code.  These are handy for finding the location of the nearest Starbucks, but they really suck when I want to get a list of all the ones in Alaska.  Considering that I will want to repeat this for many different chains, I need a solution that will let me automate it.

Using a list of all zip codes I could just brute force my way through it, querying every code in order.  With over 40000 codes in the US, this wouldn’t be too efficient – something like half a day at 1 query / second.  If there are 100 national chains that I wanted to do this for, it could take months.  It could be shortened by running several in parallel, maybe even using extra machines – but it’s still not a very elegant way of doing it.

Instead, knowing the coordinates of the zip code center, and the radius of the search I am using it should be possible to build a list of zip codes that cover the entire area, with as little overlap as possible.  Since I can’t be sure that the coordinates in my list of Zip Codes will be exactly the same as the coordinates used by the store locators, I’ll have to allow some overlap range.

For the zip code database, I am using one from http://www.free-zipcodes.com – this is a 2006 database, and while it’s not as up to date as some of the commercial ones, it should be fine for my purposes.  I find it strange that the us post office doesn’t have a zip code database for download.  There doesn’t even seem to be anything convenient to crawl to build one.

Future versions could use data from the 2000 US census to predict which zip codes are more likely to have businesses near them, so that the searches could start with the highest density areas first and then fill in the other spots later.

Posted on February 17, 2009 at 5:06 pm by Ord · Permalink
In: OBID · Tagged with: ,