Simple Zip Code Geocoding

Technology
Simple Zip Code Geocoding

mpls_20070203.jpg

The ability to geocode, or translate into latitude and longitude, postal codes is a fairly useful hack to have in your programming toolbox. Quick and dirty zip geocoding allows you to do some neat things fairly efficiently and with a minimal amount of code. Though it’s U.S. centric, it allows you to add location-based functionality to your apps without requiring any real personal information to be transfered or stored.

If your application only needs to convert a zip code (or any address) into a lat/lon coordinate, say for simple mapping purposes, the easiest solution is to use the Google Maps Geocoding API. In addition to the client-side javascript functionality, you can directly query the geocoding system from php using an http request like this:

http://maps.google.com/maps/geo?q=12345&output=xml&key=yourkeyhere

Just change 12345 to the zip (or any address) that you are looking up, and “yourkeyhere” should be your Google Map API key, which you can obtain here. Developer.com has a good PHP example for making use of the returned XML in your server-side code.

Often times, it’s useful to be able to do zip lookups based on a geographic region. Maybe you want a list of all zip codes within a certain radius or bounding box. Applications for this could include clustering map items that are near eachother, or searching a database for items that are nearest to a given location. For this, it’s really nice to have a MySQL table that contains zip codes along with their lat/lon coordinates. Fortunately, several people have compiled this sort of information from public domain data, and you can even download a full MySQL table dump here, for free.

At this point, it’s a pretty simple matter to query the database for location-based information. For instance, let’s say you have a web site with a guestbook that allows guests to leave their name and zip. You could easily whip up an application that tells your guests how many other guests are in their area by using a basic bounding box with a query like this:

SELECT guest.name from guest, zipcode
WHERE guest.zip = zipcode.zip
AND zipcode.lat < [maxlat] AND zipcode.lat > [minlat]
AND zipcode.lng < [maxlng] AND zipcode.lng > [minlng]

These are just a few ideas, but hopefully this should be enough to get you started. If you have some good ideas for other geocoding applications (or any mapping/gis hacks in general), please give us a shout in the comments.

8 thoughts on “Simple Zip Code Geocoding

  1. jher says:

    the newest version of putty now supports serial connections:

    http://www.chiark.greenend.org.uk/~sgtatham/putty/changes.html

  2. somerandomguy says:

    just found this article but it seems they no longer offer this free version, or they are hiding it extremely well on their site. I’m using PuTTY now instead as they recently added serial connection cabability. It’s free here: http://www.chiark.greenend.org.uk/~sgtatham/putty/

  3. n5pgo says:

    Hilgreave in NOT FREE!

  4. Brian Jepson says:

    n5pgo, I’m sorry to hear that they removed the free version. But as somerandomguy said, PuTTY is free, and it now supports serial connections. I’ve been using it for a while now myself, and I don’t use HyperTerminal any more.

  5. unicodemaster787 says:

    Free HyperTerminal Personal Edition is not gone from Hilgraeve. They simply “orphaned” the download page so as to confuse people and wrongfully force them to buy their Business Edition. Here it is:

    http://www.hilgraeve.com/htpe/download.html

Comments are closed.

Discuss this article with the rest of the community on our Discord server!
Tagged

I'm a tinkerer and finally reached the point where I fix more things than I break. When I'm not tinkering, I'm probably editing a book for Maker Media.

View more articles by Brian Jepson

ADVERTISEMENT

Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).

FEEDBACK