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:
-
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.
john said,
Wrote on April 15, 2007 @ 4:23 pm
Heya,
I tried to download your http://seanmountcastle.com/files/zipcode.rb however the link is broken.
If you have a sec, can you email it to me?
Thanks,
- John
sean said,
Wrote on April 15, 2007 @ 9:47 pm
John,
Very sorry about that, I’ve fixed the link in the post and emailed you a copy separately.
Enjoy,
Sean