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

Merge pull request #546 from rzane/firebird

Remove Radians, Decimal, and % Operator to work with FB
parents 39f6bda1 9447cec9
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,11 @@ module Geocoder
#
KM_IN_NM = 0.539957
##
# Conversion factor: multiply by radians to get degrees.
#
DEGREES_PER_RADIAN = 57.2957795
# Not a number constant
NAN = defined?(::Float::NAN) ? ::Float::NAN : 0 / 0.0
......
......@@ -63,26 +63,27 @@ module Geocoder
# http://www.beginningspatial.com/calculating_bearing_one_point_another
#
def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {})
degrees_per_radian = Geocoder::Calculations::DEGREES_PER_RADIAN
case options[:bearing] || Geocoder.config.distances
when :linear
"CAST(" +
"DEGREES(ATAN2( " +
"RADIANS(#{lon_attr} - #{longitude.to_f}), " +
"RADIANS(#{lat_attr} - #{latitude.to_f})" +
")) + 360 " +
"AS decimal) % 360"
"MOD(CAST(" +
"(ATAN2( " +
"((#{lon_attr} - #{longitude.to_f}) / #{degrees_per_radian}), " +
"((#{lat_attr} - #{latitude.to_f}) / #{degrees_per_radian})" +
") * #{degrees_per_radian}) + 360 " +
"AS decimal), 360)"
when :spherical
"CAST(" +
"DEGREES(ATAN2( " +
"SIN(RADIANS(#{lon_attr} - #{longitude.to_f})) * " +
"COS(RADIANS(#{lat_attr})), (" +
"COS(RADIANS(#{latitude.to_f})) * SIN(RADIANS(#{lat_attr}))" +
"MOD(CAST(" +
"(ATAN2( " +
"SIN( (#{lon_attr} - #{longitude.to_f}) / #{degrees_per_radian} ) * " +
"COS( (#{lat_attr}) / #{degrees_per_radian} ), (" +
"COS( (#{latitude.to_f}) / #{degrees_per_radian} ) * SIN( (#{lat_attr}) / #{degrees_per_radian})" +
") - (" +
"SIN(RADIANS(#{latitude.to_f})) * COS(RADIANS(#{lat_attr})) * " +
"COS(RADIANS(#{lon_attr} - #{longitude.to_f}))" +
"SIN( (#{latitude.to_f}) / #{degrees_per_radian}) * COS((#{lat_attr}) / #{degrees_per_radian}) * " +
"COS( (#{lon_attr} - #{longitude.to_f}) / #{degrees_per_radian})" +
")" +
")) + 360 " +
"AS decimal) % 360"
") * #{degrees_per_radian}) + 360 " +
"AS decimal), 360)"
end
end
......
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