Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add table_name to active_record near_scope(s)

  • Loading branch information...
commit 85e9471b77faead97a9fbbc2466d3bcfa18702df 1 parent 1df0a41
Tony Dewan authored
Showing with 13 additions and 13 deletions.
  1. +13 −13 lib/geocoder/stores/active_record.rb
26 lib/geocoder/stores/active_record.rb
View
@@ -114,26 +114,26 @@ def distance_from_sql_options(latitude, longitude, options = {})
# http://www.beginningspatial.com/calculating_bearing_one_point_another
#
def full_near_scope_options(latitude, longitude, radius, options)
- lat_attr = "#{self.table_name}.#{geocoder_options[:latitude]}"
- lon_attr = "#{self.table_name}.#{geocoder_options[:longitude]}"
+ lat_attr = geocoder_options[:latitude]
+ lon_attr = geocoder_options[:longitude]
options[:bearing] = :linear unless options.include?(:bearing)
bearing = case options[:bearing]
when :linear
"CAST(" +
"DEGREES(ATAN2( " +
- "RADIANS(#{lon_attr} - #{longitude}), " +
- "RADIANS(#{lat_attr} - #{latitude})" +
+ "RADIANS(#{table_name}.#{lon_attr} - #{longitude}), " +
+ "RADIANS(#{table_name}.#{lat_attr} - #{latitude})" +
")) + 360 " +
"AS decimal) % 360"
when :spherical
"CAST(" +
"DEGREES(ATAN2( " +
- "SIN(RADIANS(#{lon_attr} - #{longitude})) * " +
- "COS(RADIANS(#{lat_attr})), (" +
- "COS(RADIANS(#{latitude})) * SIN(RADIANS(#{lat_attr}))" +
+ "SIN(RADIANS(#{table_name}.#{lon_attr} - #{longitude})) * " +
+ "COS(RADIANS(#{table_name}.#{lat_attr})), (" +
+ "COS(RADIANS(#{latitude})) * SIN(RADIANS(#{table_name}.#{lat_attr}))" +
") - (" +
- "SIN(RADIANS(#{latitude})) * COS(RADIANS(#{lat_attr})) * " +
- "COS(RADIANS(#{lon_attr} - #{longitude}))" +
+ "SIN(RADIANS(#{latitude})) * COS(RADIANS(#{table_name}.#{lat_attr})) * " +
+ "COS(RADIANS(#{table_name}.#{lon_attr} - #{longitude}))" +
")" +
")) + 360 " +
"AS decimal) % 360"
@@ -154,8 +154,8 @@ def full_near_scope_options(latitude, longitude, radius, options)
# http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
def full_distance_from_sql(latitude, longitude, options)
- lat_attr = "#{self.table_name}.#{geocoder_options[:latitude]}"
- lon_attr = "#{self.table_name}.#{geocoder_options[:longitude]}"
+ lat_attr = geocoder_options[:latitude]
+ lon_attr = geocoder_options[:longitude]
earth = Geocoder::Calculations.earth_radius(options[:units] || :mi)
@@ -189,8 +189,8 @@ def approx_distance_from_sql(latitude, longitude, options)
# only exist for interface consistency--not intended for production!
#
def approx_near_scope_options(latitude, longitude, radius, options)
- lat_attr = "#{self.table_name}.#{geocoder_options[:latitude]}"
- lon_attr = "#{self.table_name}.#{geocoder_options[:longitude]}"
+ lat_attr = geocoder_options[:latitude]
+ lon_attr = geocoder_options[:longitude]
options[:bearing] = :linear unless options.include?(:bearing)
if options[:bearing]
bearing = "CASE " +
Please sign in to comment.
Something went wrong with that request. Please try again.