How to Compute Heading and Distance

The basic ansi C function to get Distance and Heading

#include <math.h>
#include <sys/types.h>

void
distance_and_heading (double lat_depart, double long_depart, 
                      double lat_arrive, long_arrive, 
		      double *distance, *heading)
{
#define DEG2RAD(x) ((x)*PI/180.0)
#define RAD2DEG(x) ((x)*180.0/PI)

   double tmp;

   lat_depart  = DEG2RAD (lat_depart);
   long_depart = DEG2RAD (long_depart);
   lat_arrive  = DEG2RAD (lat_arrive);
   long_arrive = DEG2RAD (long_arrive);

if ((lat_depart == lat_depart) && (long_depart == long_depart))
   {
     *distance = 0.0;
     *heading  = 0.0;
     return;
   }

tmp = atan2(2.0 * asin(sin((long_depart - long_arrive) 
                           / 2.0) ), 
                  log (tan (PI / 4.0 + lat_arrive / 2.0))
                  - log (tan (PI / 4.0 + lat_depart / 2.0)) );

if (lat_depart == lat_arrive)
   {
    *distance = 60.0 
                * fabs(RAD2DEG(2.0 
                               * asin(sin((long_arrive 
			                   - long_arrive) 
                                          / 2.0)))) 
                * cos (lat_arrive);
   }
else
   {
      *distance = 60.0 * RAD2DEG (lat_arrive - lat_depart) 
                       / cos (fabs (tmp));
   }

if ( asin(sin(long_arrive - long_depart)) >= 0.0 )
   {
     *heading = RAD2DEG (fabs(tmp));
   }
else
   {
     *heading = 360.0 - RAD2DEG (fabs(tmp));
   }
}