Module: Geocoder::Sql
Instance Method Summary collapse
-
#full_bearing(latitude, longitude, lat_attr, lon_attr, options = {}) ⇒ Object
Fairly accurate bearing calculation.
Instance Method Details
#full_bearing(latitude, longitude, lat_attr, lon_attr, options = {}) ⇒ Object
Fairly accurate bearing calculation. Takes a latitude, longitude, and an options hash which must include a :bearing value (:linear or :spherical).
Based on: www.beginningspatial.com/calculating_bearing_one_point_another
Overridden for Oracle as Oracle has no support for modulo % operator.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/geocoder/oracle.rb', line 22 def full_bearing(latitude, longitude, lat_attr, lon_attr, = {}) case [:bearing] || Geocoder.config.distances when :linear "MOD(" + "CAST(" + "DEGREES(ATAN2( " + "RADIANS(#{lon_attr} - #{longitude.to_f}), " + "RADIANS(#{lat_attr} - #{latitude.to_f})" + ")) + 360 " + "AS decimal), 360)" when :spherical "MOD(" + "CAST(" + "DEGREES(ATAN2( " + "SIN(RADIANS(#{lon_attr} - #{longitude.to_f})) * " + "COS(RADIANS(#{lat_attr})), (" + "COS(RADIANS(#{latitude.to_f})) * SIN(RADIANS(#{lat_attr}))" + ") - (" + "SIN(RADIANS(#{latitude.to_f})) * COS(RADIANS(#{lat_attr})) * " + "COS(RADIANS(#{lon_attr} - #{longitude.to_f}))" + ")" + ")) + 360 " + "AS decimal), 360)" end end |