Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Acts As Locatable

Acts As Locatable

acts_as_locatable adds typical functionality to geographically located objects, like:

  • calculating distances between objects,
  • calculating coordinates of area boundaries,
  • finding objects in given range,
  • finding closest object.

It allows for using meters or miles as measure unit, and Cosine Law, Haversine or Vincenty formulae for distance computation.

The locatable class should be an ActiveRecord model with columns for storing latitude/longitude. Usage:

class Place < ActiveRecord::Base acts_as_locatable end

The column names are assumed to be ‘latitude’ and ‘longitude’, double type. To override the names: acts_as_locatable :latitude => ‘lat’, :longitude => ‘lng’

The ‘test’ directory contains unit tests for acts_as_locatable. To run them:

  • create a MySql test database
  • configure connection details in connection.rb
  • run acts_as_locatable_test.rb

The default measure unit is meters. To override and use miles:
acts_as_locatable :unit => 'mile'
To override the unit only in certain situation use directly method variants for each unit.
The default distance calculation is the Cosine Law. To override pass the :formula option with value 'vincenty' or 'haversine':
acts_as_locatable :formula => 'vincenty'
Note that the Vincenty formula is more accurate, but may not converge for antipode locations.
To override the formula only in certain situations use directly method variants for each formula.
Tests

Bugs & Feedback

This project is hosted at RubyForge: http://actsaslocatable.rubyforge.org/ Please use the tools provided there to contact developers and submit bugs!

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all details


Membership

+ Join this railsplugin

Record Maintainer

'None'