Geocodable Model plugin

Plugin details

Keep Google Maps geocoding information available for a model.

Repositoryhttp://svn.viney.net.nz/things/rails/plugins/geocodable_model/ Tags Geo, Google, Maps LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install http://svn.viney.net.nz/things/rails/plugins/geocodable_model/

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.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: scott, 3 months ago