acts_as_geocodable is a Rails plugin that makes your applications geo-aware. A picture (er, example) is worth a thousand words:
Examples
event = Event.create :street => "777 NE Martin Luther King, Jr. Blvd.",
:locality => "Portland", :region => "Oregon", :postal_code => 97232
# how far am I from RailsConf 2007?
event.distance_to "49423" #=> 1807.66560483205
# Find our new event, and any other ones in the area
Event.find(:all, :within => 50, :origin => "97232")
# Find the nearest restaurant with beer
Restaurant.find(:nearest, :origin => event, :conditions => 'beer = true')
See the API documentation for more details.
IP-based geocoding
acts_as_geocodable adds a remote_location
method to your Rails controllers for retrieving a user's location based on their remote IP address.
@nearest_store = Store.find(:nearest, :origin => remote_location) if remote_location
Don't rely too heavily on remote_location because the location of many IP addresses cannot be determined through HostIP.
Installation
Install the plugin by executing:
script/plugin install -x http://source.collectiveidea.com/public/rails/plugins/acts_as_geocodable
Contributing
Contributions are welcome and appreciated! Grab the source from:
http://source.collectiveidea.com/public/rails/plugins/acts_as_geocodable