diff --git a/lib/geocoder/sql.rb b/lib/geocoder/sql.rb index 2ee2795c50a8d38faf60dcda853aa267c9dcc417..af0b4983a84cd6275b56da4de70fbe8514282a8e 100644 --- a/lib/geocoder/sql.rb +++ b/lib/geocoder/sql.rb @@ -11,7 +11,8 @@ module Geocoder # http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL # def full_distance(latitude, longitude, lat_attr, lon_attr, options = {}) - earth = Geocoder::Calculations.earth_radius(options[:units] || :mi) + units = options[:units] || Geocoder::Configuration.units + earth = Geocoder::Calculations.earth_radius(units) "#{earth} * 2 * ASIN(SQRT(" + "POWER(SIN((#{latitude.to_f} - #{lat_attr}) * PI() / 180 / 2), 2) + " + @@ -31,8 +32,9 @@ module Geocoder # are not intended for use in production! # def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {}) - dx = Geocoder::Calculations.longitude_degree_distance(30, options[:units] || :mi) - dy = Geocoder::Calculations.latitude_degree_distance(options[:units] || :mi) + units = options[:units] || Geocoder::Configuration.units + dx = Geocoder::Calculations.longitude_degree_distance(30, units) + dy = Geocoder::Calculations.latitude_degree_distance(units) # sin of 45 degrees = average x or y component of vector factor = Math.sin(Math::PI / 4) @@ -61,7 +63,7 @@ module Geocoder # http://www.beginningspatial.com/calculating_bearing_one_point_another # def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {}) - case options[:bearing] + case options[:bearing] || Geocoder::Configuration.distances when :linear "CAST(" + "DEGREES(ATAN2( " +