Geocoding, a must-have for social networking apps
andymilk | December 23, 2008I just started working on the “Find a Friend” portion of a social networking project, and I realized that I’ll need to filter users by their locations. I’ve integrated geocoding on apps before and performed basic lookups of cities and states using Google & Yahoo’s APIs. I’ve banged out the calculations needed to find zip codes within a certain radius of another zip code. This is my first time integrating geocoding into a Rails application and, to my delight and lack of surprise, someone has already built a plug-in that handles geocoding.
It’s called Geokit and you can find it here: http://geokit.rubyforge.org
It can do a lot. All you need is to add “lat” and “lng” float columns to the table that you need geocoding on. Install the gem & plug-in and it’s a SNAP after that. You can find the distance between two points, you can auto-geocode a location on the creation of an object, you can find all the objects within a certain distance radius. This last piece of functionality is what I needed.
So in about 90 minutes, I was able to find Geokit, install it, retrofit my tables with lat and lng, auto-geocode my objects on create, and implement a “Find a Friend” lookup. Similiar to Facebook, I want users who search for other users to find nearby users first, before searching the whole database of users. For the most part, it’s a sort by distance and then search term.
One of the slickest details of Geokit is its use of multiple geocoding sources. Here it is straight from their project page: Geocoding from multiple providers. It currently supports Google, Yahoo, Geocoder.us, Genames, and Geocoder.ca geocoders, and it provides a uniform response structure from all of them. It also provides a fail-over mechanism, in case your input fails to geocode in one service.
Nicely done.
Andy Milk is a web software designer, developer, and consultant located in the Boston, MA area. This site showcases his portfolio and approach to design and development. 




