module Geocoder::Store::ActiveRecord::ClassMethods
def near_scope_options(latitude, longitude, radius = 20, options = {})
* +:exclude+ - an object to exclude (used by the +nearbys+ method)
set to false or nil to omit the ORDER BY clause
* +:order+ - column(s) for ORDER BY SQL clause; default is distance;
* +:select+ - string with the SELECT SQL fragment (e.g. “id, name”)
See Geocoder::Configuration to know how configure default method.
set to false for no bearing calculation.
between the given point and each found nearby point;
the method to be used for calculating the bearing (direction)
* +:bearing+ - :linear or :spherical.
See Geocoder::Configuration to know how configure default units.
is added to each found nearby object.
for interpreting radius as well as the +distance+ attribute which
* +:units+ - :mi or :km; to be used.
Options hash may include:
records within a radius (in kilometers) of the given point.
Get options hash suitable for passing to ActiveRecord.find to get
#
def near_scope_options(latitude, longitude, radius = 20, options = {}) options[:units] ||= (geocoder_options[:units] || Geocoder::Configuration.units) bearing = bearing_sql(latitude, longitude, options) distance = distance_sql(latitude, longitude, options) b = Geocoder::Calculations.bounding_box([latitude, longitude], radius, options) args = b + [ full_column_name(geocoder_options[:latitude]), full_column_name(geocoder_options[:longitude]) ] bounding_box_conditions = Geocoder::Sql.within_bounding_box(*args) if using_sqlite? conditions = bounding_box_conditions else conditions = [bounding_box_conditions + " AND #{distance} <= ?", radius] end { :select => select_clause(options[:select], distance, bearing), :conditions => add_exclude_condition(conditions, options[:exclude]), :order => options.include?(:order) ? options[:order] : "distance ASC" } end