Module: Geocoder::Orm::ActiveRecord::ClassMethods

Defined in:
lib/geocoder/orms/active_record.rb

Overview

Methods which will be class methods of the including class.

Instance Method Summary collapse

Instance Method Details

#near_scope_options(latitude, longitude, radius = 20, options = {}) ⇒ Object

Get options hash suitable for passing to ActiveRecord.find to get records within a radius (in miles) of the given point. Options hash may include:

  • :units - :mi (default) or :km; to be used for interpreting radius as well as the distance attribute which is added to each found nearby object

  • :bearing - :linear (default) or :spherical; the method to be used for calculating the bearing (direction) between the given point and each found nearby point; set to false for no bearing calculation

  • :select - string with the SELECT SQL fragment (e.g. “id, name”)

  • :order - column(s) for ORDER BY SQL clause

  • :limit - number of records to return (for LIMIT SQL clause)

  • :offset - number of records to skip (for OFFSET SQL clause)

  • :exclude - an object to exclude (used by the nearbys method)



71
72
73
74
75
76
77
78
# File 'lib/geocoder/orms/active_record.rb', line 71

def near_scope_options(latitude, longitude, radius = 20, options = {})
  radius *= Geocoder::Calculations.km_in_mi if options[:units] == :km
  if connection.adapter_name.match /sqlite/i
    approx_near_scope_options(latitude, longitude, radius, options)
  else
    full_near_scope_options(latitude, longitude, radius, options)
  end
end