GeoCalculator
GeoCalculator is an extraction of the calculation methods from the Ruby Geocoder gem. Its purpose is to allow the geocoding calculation methods for models that already have latitude and longitude (obtained from the browser or an iphone app) to use distance calculations to find nearby model instances. It was extracted for use in Heat.
Installation
Add this line to your application's Gemfile:
gem 'geo-calculator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install geo-calculator
Usage
Add the line include Geocoder::Store::ActiveRecord
into your model like so:
# app/models/location.rb
class Location < ActiveRecord::Base
include Geocoder::Store::ActiveRecord
def self.
{
latitude: 'latitude',
longitude: 'longitude',
units: :mi
}
end
end
make sure that your model has a latitude
and longitude
column.
Make sure to define the geocoder_options
method, and specify the names of your latitude / longitude columns plus the units you want to use.
This will give your model a bunch of calculation methods, like .near
and .within_bounding_box
. See them all here
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request