Fun with zip codes

by on September 26, 2005

in Google/SEO,How to,Web/Net

Noticed via Tara Calashain’s excellent ResearchBuzz, here’s a great site (maps.huge.info) that lets you view zip code outlines in Google Maps. It’s pretty addictive to type in zip codes (assuming you’re in the U.S., and you have the particular bent of mind that makes you enjoy stuff like Google Maps). For the lazy among you, here’s how it looks:
Zip codes in New York
Notice that it’s doing something cool: after you’ve typed in the first zip code, you can type in more zip codes and it will draw multiple zip codes at once.

Suppose you wanted to do stuff like this yourself. First you’d want the Google Maps API. Next, you’d need a list of all the zip codes in the U.S. This is harder than it should be. From http://www.usps.com/ncsc/faq/:

Q: Where can I get a database or directory of all ZIP Codes and/or ZIP+4 codes along with the corresponding city, state, county, etc.? Is there an FTP site for downloading?
A: The information you are seeking is not available via download but is provided through our National Customer Support Center at (800) 238-3150 ….
[and then later] The Postal Service does not maintain any ZIP Code maps. The only related product we have at this time is the TIGER/ZIP+4 File.

And “TIGER/ZIP+4 File” is a link to a 404 page. Oy, thanks a lot! Grrr. Okay, so pop on over to the U.S. Census Bureau. For example, this page has a link to many good resources, including http://www.census.gov/tiger/tms/gazetteer/zips.txt which has a list of zip codes along with the city, state, latitude, and longitude of each zip code (the lat/lon is for the zip code center).

Technically, the Census Bureau calls their data Zip Code Tabulation Areas or ZCTAs. Why? As they put it,

This new entity was developed to overcome the difficulties in precisely defining the land area covered by each ZIP Code.

For example, zip codes represent postal routes and can’t always be represented with polygons. You can almost feel the contempt seething from the Census Bureau toward the U.S. Postal Service. I can believe that when Census and Postal personnel get in the same room, arguments break out and tempers flare. Sort of like Herbert Kornfeld, the Accounts Receivable Supervisor at The Onion that is always rumbling with Accounts Payable.

Okay, where were we? Postal Service: not helpful at all. Census Bureau: a great, easy-to-parse file. Okay, how about the boundary info with the shape of a zip code/ZCTA? How about this: http://www.census.gov/geo/www/cob/zt_metadata.html Oh, snap! Census Bureau 2, Postal Service 0!

Shall we delve a little deeper? Let’s do it; zip codes are fun. By the way, if you’re not a complete and utter nerd, or you don’t have hours to kill digging into files, the huge.info site sells a DVD with cleaner data in an easier format.

Okay, let’s examine the zip code for 94043 (where Google’s headquarters are located). Go to http://www.census.gov/geo/www/cob/z52000.html#ascii and save the file for California and decompress the zip file. The files are available in three formats, but we’re sticking with straight ASCII. Inside the zip file there are two files, a tiny one and a big one. In the tiny one, look for the zip code you’re interested in (94043 in this example):

2465
“94043″
“94043″
“Z5″
“5-Digit ZCTA”

This entry means that in the big file, the zip code 94043 is represented with an ID of 2465. If you look in the big file, you’ll find the data for that polygon in latitude/longitude format:

2465 -0.122065371904532E+03 0.374225573395062E+02
-0.122077973000000E+03 0.374482390000000E+02
-0.122077373000000E+03 0.374500390000000E+02
…. ….
-0.122077973000000E+03 0.374482390000000E+02
END

The first coordinate appears to be the center of the ZCTA, so chop off the first line and the END line and put the resulting lines in a file called 94043. Now fire up gnuplot and type these commands:

set terminal png
set output "94043.png"
set nokey
set title "Zip code: 94043"
set xlabel "Longitude"
set ylabel "Latitude"
set grid
plot '94043' with lines

Alrighty, let’s see how we did. Here’s the zipcode on the original application:

Original map of 94043 zip code

And here’s our Gnuplot map:
Gnuplot plot of 94043 zip code

There’s just too many fun things to do in the world. :)

Update: If you enjoy playing with zip codes, Gary Price pointed me to http://www.melissadata.com/Lookups/index.htm where you can look up neat things like demographics and business counts.

{ 55 comments… read them below or add one }

Galina Sh. September 26, 2005 at 1:41 am

Strangely enough, I was just looking for zipcode to town, state and back information.

zips.txt file is neat, unfortunately outdated at least 5 years. It’s missing “new” zipcodes from both places I happened to live in in the last couple of years (both East and West coast). Makes one wonder how often they shuffle zipcodes around.

Reply

Tobias Kluge September 26, 2005 at 1:50 am

Hey Matts,

when will you extends these nice more-content containing Google maps to countries outside the US? It would be nice to get some more data for Europe. :)

Tobias

Reply

Andi September 26, 2005 at 6:22 am

Particularly interesting because so much demographic data is linked to zipcodes… I’d like to see a smaller granulation but zipcodes work for many things. :)

Reply

michael September 26, 2005 at 8:57 am
paul September 26, 2005 at 9:24 am

hey there

I emailed Research Buzz as well, but in case you have not done multiple requests, it kicks you off after several requests (not sure how many- was not counting) and tells you to come back in 2 hours. It may be doing this via the IP since I cleared cache, cookies, history, etc and still received the same message.

Reply

Matt September 26, 2005 at 10:10 am

Michael, thanks for the pointers! Looks like that first link pre-dates the Maps API. Back then you had to use the quadtree specification, I think, instead of just giving a polyline with lat/lon coordinates. I’m glad that the API makes it easier. This stuff is just fun. :)

Reply

Harith September 26, 2005 at 3:01 pm

Hi Matt

And the winner is …:)

Assuming that number of comments posted per an article represents the visitors wish to see more of the same, here are the Superstars:

One month

Alerting site owners to problems

Filing a reinclusion request

Remove result

Data:
====================================

September 2005

UI fun: Remove result :Comments (51)

AdWords, AdSense, and the Google blog :Comments (8)

Alerting site owners to problems :Comments (60)

Filing a reinclusion request :Comments (60)

Bacon polenta :Comments (39)

Measuring freshness :Comments (15)

One month :Comments (72)

Book Review: The Search :Comments (9)

What’s an update? :Comments (34)

======================================

August 2005

Bloglines :Comments (10)

Dashes vs. underscores :Comments (37)

Seeing nofollow links :Comments (25)

Smart is sexy :Comments (11)

I do not wish my screensaver to lock my computer, thank you. :Comments (11)

Just call me Rick :Comments (6)

UI fun: Better queries :Comments (18)

UI fun: Better snippets :Comments (16)

SEO Mistakes: sneaky JavaScript :Comments (35)

SEO Mistakes: link exchange emails :Comments (18)

=========================================

July 2005

Things to do and eat in Silicon Valley :Comments (14)

Q: Why doesn’t my site show in SafeSearch?, or “Do you hate Metallica?” :Comments (7)

.htaccess 101: how to password protect a directory :Comments (7)

===============================================================

And yes…

“There’s just too many fun things to do in the world.” ;-)

Reply

Brian September 27, 2005 at 10:04 am

Harith’s methodology, whether he realizes it or not, resembles SEO…note that Matt has to approve comments, so the true number is hidden. link: command, anyone? ;)

Reply

Victor Caballero September 27, 2005 at 11:50 am

The MAPS API is very cool. Does anyone know if there is a way to zoom in and only display the zip code and then map a specific address?

Reply

Vincent September 28, 2005 at 5:57 am

Hi Matt

When will this technology be extended into the UK? We are real interested in using this for an upcoming project thats in development stage at the moment.

Reply

Vincent September 28, 2005 at 6:03 am

Sorry I forgot to add to above that will this also be available for commercial use that can be implemented into projects for www and mobile web?

Thanks again.

Reply

Bob L. September 28, 2005 at 8:04 am

Matt,

Great stuff. Maps is such a cool app that I am brainstorming for a use on our web site.

I was reading an example that was referenced at xml.com and came across this terrific app http://www.housingmaps.com/. If you are searching for a house, as I am, it combines a few of the functions that I already use

1. The property search
2. The mapping of the property
3. The photos of property)

Awesome stuff.

Bob L.

Reply

knut September 28, 2005 at 1:24 pm

Funny…
ever recognized that “zip-code”, “zip code” and “zipcode” differs in google?
I thought that “zip-code” would be stemmed to “zipcode”. But the results are different. Google is a myth ;)

I love GoogleEarth!
-knut

Reply

Harith October 1, 2005 at 6:17 am

Hi Matt

Long time no blogging.

C´mon.. say something ;-)

Reply

Fionn October 1, 2005 at 4:04 pm

Totally fascinating now I need some time to play. Now if Google could just build me a widget that would increase my time by 100%!!!.

Reply

Matthew October 3, 2005 at 10:30 am

> Makes one wonder how often they shuffle zipcodes around.

Quite a lot, actually. I do some work with mail-list management and see evidence of this all the time. Actually, though the source escapes me at the moment, there IS somewhere with the USPS where you can get updated zip databases every month.

Reply

Sean Scott October 3, 2005 at 10:50 am

anyone seen an example of mapping county bounderies using google map. Or should i be asking how would you go about mapping the borders of a county via google maps.

Reply

Gator99 October 10, 2005 at 9:47 am

In actual practice, I’ve found that the lon/lat data from the census site (gazateer) is not very accurate. For a commerical application, you’d need better data.

Reply

mac October 11, 2005 at 2:43 pm

Matt,

I have a question for you. Can you please read this group post then reply?

http://groups.google.com/group/google-sitemaps/browse_thread/thread/c1834900ea40e74e/8ecdca81236b6f57#8ecdca81236b6f57

Thanks,
Mac

Reply

mr_tim October 21, 2005 at 3:21 am

Think of the fun we could have in the UK if Google stepped up to provide a decent geocoder for us Google Map API fanatics

Reply

DDS Web Design Blog October 21, 2005 at 7:38 am

wow, that is awesome, i love google maps/google local, so useful…since its release ive stopped using mapquest compeltely, its just too much better than mapquest

Reply

John Coryat October 26, 2005 at 4:49 am

Matt,

I recently added both city/town and county boundary mapping to the application.

http://maps.huge.info

-John Coryat, author.

Reply

Matt October 26, 2005 at 12:08 pm

Nice–thanks for mentioning that, John! I love plotting town boundaries..

Reply

Brett October 27, 2005 at 8:06 am

This is very cool software. I don’t think I have ever seen any kind of software draw out the area that a zipcode falls within. Pretty cool stuff.

Reply

Adam October 30, 2005 at 3:53 am

Hi Matt,

I have just found great Google Maps site similar to this, but with whole world coverage. Maybe interesting for others as well. See http://www.maplandia.com.

-Adam

Reply

Online Dictionary November 8, 2005 at 12:01 am

Had been playing with the tigerline database and and the geocoding and i think having it natively in your system seems costly than using the geocode us webservice.

Reply

Steve A November 11, 2005 at 7:51 am

I have a list of zip codes that I want to display on Google Map (eg, with a marker – I’m not trying to show boundaries). I’d like to show them all at once, not one at a time – have you seen a site that does htis?

Reply

victor caballero November 18, 2005 at 10:41 pm

I know this is somewhat unrelated to this thread, but I was curious as to why some addresses like this example show up as a different address when mapped by Google.

http://maps.google.com/maps?oi=map&q=301+N+Orange+Grove+Blvd,+Pasadena,+CA+91103

I found it odd and thought there must be an explanation????

Thanks in advance.

Victor

Reply

Mike Chau November 24, 2005 at 7:34 pm

Does anyone know if there is something simalar for Canada?

Reply

Chung January 4, 2006 at 6:14 am

I wish they could make that kind of map for Italy aswell. Here in Italy the companies are so lame…

Reply

online sudoku February 23, 2006 at 6:47 am

I wish they made smoething like this to the UK!!

Reply

Mush March 2, 2006 at 8:49 am

When does this tool will be available for another countries?

Reply

Adam Yax March 5, 2006 at 7:20 pm

multi-country zip codes would be helpfull for us as well. If anyone finds one please post.

Reply

Edward March 21, 2006 at 5:02 pm

We use this tool to verify orders on our mens underwear site http://www.nuwear.com

Reply

John Wehr April 10, 2006 at 7:55 pm

I’ve made a similar database and associated PHP class available for sale at:

http://zip-code-boundaries.com/

Hopefully it will be useful for companies who want ZIP Code outlines in their web applications.

Reply

Amber October 5, 2006 at 10:50 am

I have looked the web over for a site that will allow you to insert a zip code, have it mark that zip code on a map, and then save it to the map. Then be able to add another zip code and repeat the procedure. Sort of like planning a route based on zip codes, or taking a list of random zip codes and plotting them on a map. Any help would be great! am

Reply

Colin Crawford November 3, 2006 at 4:18 pm

Man I wish this was available in Australia. That is such a cool tool to have especially for working out freight charges for distribution.

Reply

Expired Domain Names January 14, 2007 at 2:11 pm

I wish they made smoething like this to the UK!!

Reply

Brian February 28, 2007 at 11:50 am

I have a list of zip codes and I want to show their concentration on a map, kind of like a precipitation weather map. How do I do that?

Reply

John May 12, 2007 at 8:54 am

It helps us to keep orders from coming back as undeliverable our online store for men’s underwear ABCunderwear.com We find it very helpful

Reply

Rick Vidallon May 22, 2007 at 6:09 am

I searched the regional term ‘Virginia Web Design’ and you displayed the regional results incorrectly.
You show map tag ‘C’ as Ciniva but this should be VISIONEFX.

The same thing happens when you search the local term ‘ Virginia Beach Web Design. You show map tag ‘A’ as Ciniva but this should be VISIONEFX.

Why are the map tags inaccurate?

Reply

Jon May 22, 2007 at 10:37 am

The post office doesn’t provide the lists of ZIP Codes for download, but there are quite a few companies out there that are licensed to resell the data:
http://www.zipcodedownload.com/
http://www.greatdata.com/
http://www.melissadata.com/

Most of them have databases with latitude and longitude coordinates included.

Reply

Simon July 31, 2007 at 11:03 am

That’s a cool. I didn’t realize zip codes were so irregular shaped and weird looking. Check out my zip code 90211 and the craxy shaped LA zip codes arount it.

Reply

James September 12, 2007 at 7:28 pm

I have built a set of tools to work on zip codes. Take a look at http://www.mapszipcode.com. The site is complete but I intend on adding more tools and info as time permits.

Reply

Darrin Clement September 18, 2007 at 6:40 pm

This is very fun and a great application of map data with Google. Important to remind anyone doing serious analysis though, that ZCTAs are very much not “ZIP Codes”. Commercial companies (like Maponics – http://www.maponics.com – where I work) use much more accurate and current data than ZCTAs. Of course, ZIP Codes are not really polygons anyway – they are collections of houses that have the same ZIP Code, but that’s a whole other story.

Reply

Arnie November 18, 2007 at 11:15 am

I was just looking for this exact tool for a blog idea I have. Managed to find this post in 10 minutes. I love the web.

Reply

US zip code map January 9, 2008 at 2:30 am

I would recommend http://www.zipcodesmapped.com/ for any US zip code map.
You can use this to find any US zip code maps. You can search by (City, State OR Zip). they have all the maps showing zip codes and major mile streets in all of the united states. The service is free. Search for five Digit Zip Code and find the Maps for all 50 states. A Free ZIP Code Finder which can do wonders for you.

Reply

Jay August 20, 2008 at 9:32 am

Does anyone know of a tool that would let you enter a primary zip code and then load up a 2nd list of multiple zip codes so that you can plot them on a state, regional or US map?

Thanks,

Jay
discussions@surveysquare.com

Reply

Jimmy October 18, 2008 at 8:36 pm

You can get the free monthly updates ZIP code database from the following URL. It does not have the boundary information as mentioned by Matt earlier. However, the ZIP code list is good for validation purpose. Nothing wrong to give it a try as it is FREE.

http://www.zipcodeworld.com/zipcodefree.htm

Reply

Allen October 28, 2008 at 1:50 pm

Like Amber, I need the ability to save these (3 or 5 digit) zip code boundaries to “My Maps” in google, to track our marketing campaigns. Does anyone know if this is possible or available?

Thanks

Reply

JerryGarciuh September 1, 2009 at 11:56 am

Thanks for the census zip code link! Made my day!

Reply

Robert August 18, 2010 at 7:53 am

Definitely helps with my shipping! Thanks for the post!

Reply

Ansel Grogan August 18, 2010 at 2:37 pm

Hi all,

Anyone have an idea how to combine multiple contiguous zip codes and plot an outline of the combined area >?

Reply

Greg Williams January 6, 2011 at 10:09 am

I was looking for a site to map a bunch of addresses/zipcodes onto a Google map and found this thread.

Here’s what I ended up using:
http://www.batchgeo.com

A great service with highly editable output. Exactly what I was looking for.

Reply

Owen Brunette February 22, 2011 at 1:12 pm

Unfortunately when you do contact the USPS for their list of Zip codes this is the significant paragraph of the response you get back:

The USPS offers the AMS API CD as an alternative, which has all the addressing needs on it that would have been provided through the Address API. The Address Matching System Application Programming Interface is $3,800/ annually for in-house use. This allows the customer to place the data in one location on one server and develop on one platform. If wish to develop on multiple platforms or develop software for resale, there are additional charges.

They have an online API but you need to be a USPS shipping customer using it for that purpose in order to get the API account authorized.

Oh well. There are other ways to get at the data.

Reply

Leave a Comment

If you have a question about your site specifically or a general question about search, your best bet is to post in our Webmaster Help Forum linked from http://google.com/webmasters

If you comment, please use your personal name, not your business name. Business names can sound salesy or spammy, and I would like to try people leaving their actual name instead.

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: