= GeocodableModel If you find this plugin useful, please consider a donation to show your support! http://www.paypal.com/cgi-bin/webscr?cmd=_send-money Email address: jonathan.viney@gmail.com == Instructions Keep Google Maps geocoding information available for a model. == Usage Set your api key in config/environment.rb Geocode.api_key = "123123123123" Specify geocodable_model on the model. The block given should return the address string used for geocoding. class Group < ActiveRecord::Base geocodable_model do |group| [group.address1, group.address2].join(', ') end end Whenever a model object is saved and the address value has changed, the geocode object will be updated. Create the geocodes table, see test/schema.rb A daemon running in the background fills in geocoding information as it is needed by running: Geocode.populate This could be run every 5 - 10 seconds from a daemon. By default a geocoding accuracy of 7 or 8 is required for the information to be considered valid. Geocoding data can then be accessed on the model: g = Group.find(:first) g.geocode.latitude g.geocode.longitude g.to_geocode == [g.geocode.latitude, g.geocode.longitude] If the geocoding was unsuccessful g.geocode.geocoding_result will contain a short error message.