def bearing_between(point1, point2, options = {})

      # set default options
      options[:method] ||= Geocoder.config.distances
      options[:method] = :linear unless options[:method] == :spherical

      # convert to coordinate arrays
      point1 = extract_coordinates(point1)
      point2 = extract_coordinates(point2)

      # convert degrees to radians
      point1 = to_radians(point1)
      point2 = to_radians(point2)

      # compute deltas
      dlat = point2[0] - point1[0]
      dlon = point2[1] - point1[1]

      case options[:method]
      when :linear
        y = dlon
        x = dlat

      when :spherical
        y = Math.sin(dlon) * Math.cos(point2[0])
        x = Math.cos(point1[0]) * Math.sin(point2[0]) -
            Math.sin(point1[0]) * Math.cos(point2[0]) * Math.cos(dlon)
      end

      bearing = Math.atan2(x,y)
      # Answer is in radians counterclockwise from due east.
      # Convert to degrees clockwise from due north:
      (90 - to_degrees(bearing) + 360) % 360
    end
def bearing_between(point1, point2, options = {})

      # set default options
      options[:method] ||= Geocoder.config.distances
      options[:method] = :linear unless options[:method] == :spherical

      # convert to coordinate arrays
      point1 = extract_coordinates(point1)
      point2 = extract_coordinates(point2)

      # convert degrees to radians
      point1 = to_radians(point1)
      point2 = to_radians(point2)

      # compute deltas
      dlat = point2[0] - point1[0]
      dlon = point2[1] - point1[1]

      case options[:method]
      when :linear
        y = dlon
        x = dlat

      when :spherical
        y = Math.sin(dlon) * Math.cos(point2[0])
        x = Math.cos(point1[0]) * Math.sin(point2[0]) -
            Math.sin(point1[0]) * Math.cos(point2[0]) * Math.cos(dlon)
      end

      bearing = Math.atan2(x,y)
      # Answer is in radians counterclockwise from due east.
      # Convert to degrees clockwise from due north:
      (90 - to_degrees(bearing) + 360) % 360
    end
Bearing between two points on Earth.
 Returns a number of degrees from due north (clockwise).

 See Geocoder::Calculations.distance_between for
 ways of specifying the points. Also accepts an options hash:

 * <tt>:method</tt> - <tt>:linear</tt> or <tt>:spherical</tt>;
   the spherical method is "correct" in that it returns the shortest path
   (one along a great circle) but the linear method is less confusing
   (returns due east or west when given two points with the same latitude).
   Use Geocoder.configure(:distances => ...) to configure calculation method.

 Based on: http://www.movable-type.co.uk/scripts/latlong.html