module Geocoder::Sql
def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {})
http://www.beginningspatial.com/calculating_bearing_one_point_another
Based on:
(:linear or :spherical).
and an options hash which must include a :bearing value
Fairly accurate bearing calculation. Takes a latitude, longitude,
#
def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {}) 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" 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}))" + ") - (" + "SIN(RADIANS(#{latitude.to_f})) * COS(RADIANS(#{lat_attr})) * " + "COS(RADIANS(#{lon_attr} - #{longitude.to_f}))" + ")" + ")) + 360 " + "AS decimal) % 360" end end