github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

collectiveidea / acts_as_geocodable

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 118
    • 10
  • Source
  • Commits
  • Network (10)
  • Issues (1)
  • Downloads (3)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (3)
    • v1.0.2
    • v1.0.1
    • v1.0.0
Sending Request…
Click here to lend your support to: acts_as_geocodable and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A Rails plugin that makes your applications geo-aware. — Read more

  cancel

http://graticule.rubyforge.org/plugin.html

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Regenerated gemspec for version 1.0.2 
danielmorrison (author)
Thu Feb 04 12:40:50 -0800 2010
commit  3d180eb825ced5bc0de2a6e56a6f1adbe53f7d0b
tree    057249843bfe6c8a7ebd2c7763e6224f3b6b798d
parent  86cce985a7b26df809d30ad1affce037021537a0
acts_as_geocodable /
name age
history
message
file .gitignore Wed Dec 02 18:23:10 -0800 2009 Update validates_as_geocodable to take a :preci... [brandon]
file CHANGELOG Fri Aug 08 01:50:51 -0700 2008 Added further documentation and tests - Added C... [Andrew Donaldson]
file MIT-LICENSE Sun Oct 01 22:08:33 -0700 2006 Updated README and added license information [danielmorrison]
file README Wed Oct 21 01:49:18 -0700 2009 Setup for gemcutter [danielmorrison]
file Rakefile Wed Oct 21 01:49:18 -0700 2009 Setup for gemcutter [danielmorrison]
file VERSION Thu Feb 04 12:40:46 -0800 2010 Version bump to 1.0.2 [danielmorrison]
file about.yml Tue Feb 13 06:33:02 -0800 2007 renamed meta.yml to about.yml [brandon]
file acts_as_geocodable.gemspec Thu Feb 04 12:40:50 -0800 2010 Regenerated gemspec for version 1.0.2 [danielmorrison]
directory generators/ Sat Oct 04 13:10:10 -0700 2008 Added precison to the Geocode model, added new ... [danielmorrison]
file install.rb Sun Oct 01 19:05:53 -0700 2006 Initial commit of acts_as_geocodable [danielmorrison]
directory lib/ Thu Feb 04 12:40:01 -0800 2010 Setting :precision in validates_as_geocodable i... [danielmorrison]
directory rails/ Wed Oct 21 01:42:08 -0700 2009 Moving files to prepare for gemification [danielmorrison]
directory test/ Thu Feb 04 12:40:01 -0800 2010 Setting :precision in validates_as_geocodable i... [danielmorrison]
file uninstall.rb Sun Oct 01 19:05:53 -0700 2006 Initial commit of acts_as_geocodable [danielmorrison]
README
= acts_as_geocodable

acts_as_geocodable is a plugin to help build geo-aware applications. It automatically geocodes your models when they are 
saved, giving you the ability to search by location and calculate distances between records.

== Usage

  event = Event.create :street => "777 NE Martin Luther King, Jr. Blvd.",
    :locality => "Portland", :region => "Oregon", :postal_code => 97232
    
  event.geocode.latitude                                #=> 45.529100000000
  event.geocode.longitude                               #=> -122.644200000000
  
  event.distance_to "49423"                             #=> 1807.66560483205
  
  Event.find(:all, :within => 50, :origin => "97232")
  
  Event.find(:nearest, :origin => "Portland, OR")
  
== Upgrading

If you're upgrading from a previous version of this plugin, note that :city has been renamed to :locality to be 
consistent with Graticule 0.2.  Create a migration that has:

  rename_column :geocodes, :city, :locality

Also remember to change your mapping in your geocodable classes to use the :locality key instead of :city:

class Event < ActiveRecord::Base
  acts_as_geocodable :address => {:street => :address1, :locality => :city,
    :region => :state, :postal_code => :zip}
end

== Installation

Graticule[link:http://rubyforge.org/projects/graticule] is used for all the heavy lifting.

  gem install graticule --include-dependencies

Install as a plugin

  script/plugin install git://github.com/collectiveidea/acts_as_geocodable.git
  
Or, install as a gem
  
  gem install acts_as_geocodable --source=http://gemcutter.org
  

== Upgrading
  
Before October 2008, precision wasn't included in the Geocode model. Make sure you add a string precision column to your 
geocode table if you're upgrading from an older version, and update Graticule.

== Configuration

Create the required tables
  
  script/generate geocodable_migration add_geocodable_tables
  rake db:migrate

Set the default geocoder in your environment.rb file.

  Geocode.geocoder = Graticule.service(:yahoo).new 'your_api_key'

Then, in each model you want to make geocodable, add acts_as_geocodable.

  class Event < ActiveRecord::Base
    acts_as_geocodable
  end

The only requirement is that your model must have address fields. By default, acts_as_geocodable looks for attributes 
called +street+, +locality+, +region+, +postal_code+, and +country+.  To change these, you can provide a mapping in the 
<tt>:address</tt> option:

  class Event < ActiveRecord::Base
    acts_as_geocodable :address => {:street => :address1, :locality => :city, :region => :state, :postal_code => :zip}
  end

If that doesn't meet your needs, simply override the default +to_location+ method in your model, and return a 
Graticule::Location with those attributes set.

acts_as_geocodable can also update your address fields with the data returned from the geocoding service:

  class Event < ActiveRecord::Base
    acts_as_geocodable :normalize_address => true
  end

== IP-based Geocoding

acts_as_geocodable adds a remote_location method in your controllers that uses http://hostip.info to guess remote users 
location based on their IP address.

  def index
    @nearest = Store.find(:nearest, :origin => remote_location) if remote_location
    @stores = Store.find(:all)
  end

Keep in mind that IP-based geocoding is not always accurate, and often will not return any results.

== Development

The source code is available at:
   http://github.com/collectiveidea/acts_as_geocodable
   git://github.com/collectiveidea/acts_as_geocodable.git

Patches and suggestions are welcome!

== To Do

* Documentation!!!
* configurable formulas
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server