True North heading between two points Function()

May 27, 2010 at 1:48 PM

Hi ..

it's really amazing project that can help us to develop navigation systems.

in my navigation project i wanted to calculate true north heading between two points and didn't find any reference that discuss' it clearly 

I'm just wondering if there's any method in this project that can calculate true north heading between two Coordinates..

If not could you take me a web reference about this equations.

Thanks alot .

Coordinator
May 27, 2010 at 4:17 PM

 

      /// <summary>
      /// Accepts two coordinates in degrees.
      /// </summary>
      /// <returns>A double value in degrees.  From 0 to 360.</returns>
      public double Bearing(double p1Lat, double p1Lng, double p2Lat, double p2Lng)
      {
         var latitude1 = ToRadian(p1Lat);
         var latitude2 = ToRadian(p2Lat);
         var longitudeDifference = ToRadian(p2Lng - p1Lng);

         var y = Math.Sin(longitudeDifference) * Math.Cos(latitude2);
         var x = Math.Cos(latitude1) * Math.Sin(latitude2) - Math.Sin(latitude1) * Math.Cos(latitude2) * Math.Cos(longitudeDifference);

         return (ToDegree(Math.Atan2(y, x)) + 360) % 360;
      }

      /// <summary>
      /// Converts degrees to Radians.
      /// </summary>
      /// <returns>Returns a radian from degrees.</returns>
      public static Double ToRadian(Double degree)
      {
         return (degree * Math.PI / 180.0);
      }

      /// <summary>
      /// To degress from a radian value.
      /// </summary>
      /// <returns>Returns degrees from radians.</returns>
      public static Double ToDegree(Double radian)
      {
         return (radian / Math.PI * 180.0);
      }
May 27, 2010 at 4:41 PM

Thank you very much for this help
I've lost a long time without any solution.
My wish is to be added to this procedural GMap.net.
Thanks again