GeoKit: My First Rails Plug-in
This is a follow-up to my last post on distance queries in Rails. Since that post, I’ve enlisted the help of Andre Lewis at Earthcode.com to help super-charge the feature set. If you don’t know Andre, he’s the author of the upcoming book Beginning Google Maps Applications with Rails and Ajax, so I think he’s uniquely qualified.
The Rdoc is the best place to go to learn more. We’ve set it up on RubyForge. But just to whet your appetite, just imagine not having to code any nasty trigonometry into your SQL to include distance columns or conditions. Or imagine having ready access to Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders separately or in a failover configuration. If that’s not enough, imagine integrating geocoders into your finders! For instance:
1 2 3 |
stores = Store.find(:all, :origin => “100 Spear St, San Francisco, CA“, :conditions => “distance < 10“) |
where the origin value serves as the anchor for the distance calculation and gets geocoded on the fly.
All this is done through a declaration like this:
1 2 3 4 5 6 |
class Store < ActiveRecord::Base belongs_to :company # Enables distance calculations and sweet, clean distance queries. acts_as_mappable end |
The goal of the plug-in is to clean up client code for location-based applications. I think we’ve succeeded. Enjoy everyone!