Skip to content
Snippets Groups Projects
Commit ee7e5223 authored by Alex Reisner's avatar Alex Reisner
Browse files

Make Geocoder::Sql respect Geocoder::Configuration.

parent 879a6739
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,8 @@ module Geocoder ...@@ -11,7 +11,8 @@ module Geocoder
# http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL # http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
# #
def full_distance(latitude, longitude, lat_attr, lon_attr, options = {}) 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(" + "#{earth} * 2 * ASIN(SQRT(" +
"POWER(SIN((#{latitude.to_f} - #{lat_attr}) * PI() / 180 / 2), 2) + " + "POWER(SIN((#{latitude.to_f} - #{lat_attr}) * PI() / 180 / 2), 2) + " +
...@@ -31,8 +32,9 @@ module Geocoder ...@@ -31,8 +32,9 @@ module Geocoder
# are not intended for use in production! # are not intended for use in production!
# #
def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {}) def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {})
dx = Geocoder::Calculations.longitude_degree_distance(30, options[:units] || :mi) units = options[:units] || Geocoder::Configuration.units
dy = Geocoder::Calculations.latitude_degree_distance(options[:units] || :mi) 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 # sin of 45 degrees = average x or y component of vector
factor = Math.sin(Math::PI / 4) factor = Math.sin(Math::PI / 4)
...@@ -61,7 +63,7 @@ module Geocoder ...@@ -61,7 +63,7 @@ module Geocoder
# http://www.beginningspatial.com/calculating_bearing_one_point_another # http://www.beginningspatial.com/calculating_bearing_one_point_another
# #
def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {}) def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {})
case options[:bearing] case options[:bearing] || Geocoder::Configuration.distances
when :linear when :linear
"CAST(" + "CAST(" +
"DEGREES(ATAN2( " + "DEGREES(ATAN2( " +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment