Getting the Lat/Long for a Zipcode

I’ve uploaded a short Ruby script which uses Google maps to obtain the lat/long given a zipcode. I needed this since the Cartographer RoR plug-in takes coordinates in the form of lat/long and my customers will only provide me with their zipcodes or complete addresses. Obviously in my Rails web-app I’m storing the lat/long in the DB so I don’t repeatedly query Google Maps. The class simply returns a hash and is trivial to use:

{lang=“ruby”} coords = GMap.to_latlng(“90210”) lat = coords[:lat] lng = coords[:lng]

Download zipcode.zip Updated 2007: This has basically been supplanted by the excellent GeoKit for Rails.