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, 
                     :o rigin => "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!

This entry was posted in Open Source, Ruby, Ruby on Rails. Bookmark the permalink.

8 Responses to GeoKit: My First Rails Plug-in

  1. Pingback: GeoKit: Geocoding and Location Finder Plugin for Rails

  2. Jordan Brock says:

    This is absolutely fantastic. I’ve been wanting to add geocoding to a website I’ve been working on, and with Google launching Maps and Local Search in Australia just the other day, this is just perfect timing.

    Thank you both for a great plugin.

  3. Bill,

    Cool stuff! I love the finder.

    I have similar goals for Graticule and the acts_as_geocodable plugin. The vision is that Graticule will be an all-purpose geo library, with support for all the geocoders, distance calculations, etc, and the plugin would add geocoding to models, along with finders.

    Are you interested in joining forces?

    Brandon

  4. Jordan Brock says:

    Further to my last comment, I’ve integrated the plugin with this site – School Seek – and am using it to allow people to do a distance based search for schools.

    Once again, thanks for the plugin. I’ve got a very happy client today!

    Cheers,
    Jordan

  5. Pingback: Rails on the road » Archivio Blog » GeoKit: Geocoding and Location Finder Plugin for Rails

  6. Have you thought about moving the core functionality into a generic Ruby gem, with the plug-in wrapped around that? This seems like it’d be useful in many more places than just Rails. — Ernie P.

  7. Hey Ernie,

    Hey There,

    Thanks for the suggestion. You are definitely right, there is no reason why this needs to be packaged entirely as a plugin. The plugin started as an acts_as_mappable mix in for the most part, so it could only be a plugin at that point.

    Then when I enlisted Andre to help mix in the geocoder stuff, that’s where we started to get into gem territory. While its not as elegant, you can certainly thieve the geocoder code out if that’s what you are interested in. Just remember to take care of the keys.

    Many thanks for the feedback and we’ll definitely give some thought into alternative packaging.

    Bill

  8. I would like to propose not to hold back until you earn enough money to order different goods! You should just get the loan or just consolidation loans and feel yourself fine

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>