0.0
No commit activity in last 3 years
No release in over 3 years
Use ruby geocoder calculation methods without geocoding
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

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.geocoder_options
    {
      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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request