If you didn't write the code, then all bets are off. I guarantee you that it is **not good code, especially not for Arduino**, and you would need to check every result to make sure it is sensible.

If there is anyone out there

As I suggested, take a look at neoGPS.

Otherwise, my own library stores lat/lon in units of degrees*1000000. The function to calculate heading and distance between waypoints over short distances (<10 km) is accurate to better than 0.1 m but very simple, using the equirectangular approximation.

Also includes code to find a new waypoint at given bearing (degrees) and distance in meters from an existing position.

```
// find the bearing and distance in meters from point 1 to 2,
// using the equirectangular approximation
// lat and lon are degrees*1.0e6, 10 cm precision
// for higher accuracy, radius to geodetic latitude can be calculated (now commented out)
double course_to(long lat1, long lon1, long lat2, long lon2, double* distance) {
double dlam,dphi,radius;
//double b=6378000.0,a=6357000.0; //equatorial and polar radii of Earth
dphi = DEG2RAD*(lat1+lat2)*0.5e-6; //average latitude in radians
double cphi=cos(dphi);
//double sphi=sin(dphi);
dphi = DEG2RAD*(lat2-lat1)*1.0e-6; //differences in degrees
dlam = DEG2RAD*(lon2-lon1)*1.0e-6;
dlam *= cphi; //correct for latitude
double bearing=RAD2DEG*atan2(dlam,dphi);
if(bearing<0) bearing=bearing+360.0;
/* optional radius to geodetic (standard) latitude
double a2=a*a;
double b2=b*b;
double s2=sphi*sphi;
double c2=cphi*cphi;
radius = sqrt((a2*a2*c2 + b2*b2*s2)/(a2*c2 + b2*s2));
*/
radius = 6371000.0;
*distance = radius * sqrt(dphi*dphi + dlam*dlam);
return bearing;
}
//
// find latitude and longitude (lat2,lon2) of a point,
// given bearing (degrees) and distance (meters), lat1, lon1
//
// **great circle route on spherical Earth assumed**
//
// input and output (lat,lon) are long integers in degrees*1e6
// on ATMegas, this is less accurate due to single precision floats
/*
void bearing_shoot(float bearing, float distance, long lat1, long lon1, long *lat2, long *lon2)
{
float phi1,lam1,d,phi2;
float R=6371000.0; //mean Earth radius in meters
float theta = bearing*DEG2RAD;
d = distance/R; //arc length
phi1 = DEG2RAD*lat1*1.0e-6; //convert to radians
lam1 = DEG2RAD*lon1*1.0e-6;
phi2 = asin(sin(phi1)*cos(d) + cos(phi1)*sin(d)*cos(theta));
*lat2 = (long) 1.0e6*phi2*RAD2DEG;
*lon2 = (long) 1.0e6*(lam1 + atan2(sin(theta)*sin(d)*cos(phi1), cos(d)-sin(phi1)*sin(phi2)))*RAD2DEG;
}
*/
// this version of bearing_shoot uses the equirectangular approximation.
// GPS coordinates assumed to be long integers, degrees*10^6 (10 cm precision)
// tests show it to be more accurate for short distances than the great circle
// version above, but consumes far less program memory
void bearing_shoot (float bearing, float distance, long lat1, long lon1, long *lat2, long *lon2)
{
float d,phi1;
float R=6371000.0; //mean Earth radius in meters
long dlat, dlon;
float theta = bearing*DEG2RAD;
d = RAD2DEG*distance/R; //arc length in degrees
phi1 = DEG2RAD*lat1*1.0e-6; //convert lat to radians
dlat = d*cos(theta)*1.0e6; //latitude change in degrees*10^6
dlon = d*sin(theta)*1.0e6/cos(phi1); //longitude change, corrected for latitude
*lat2 = lat1 + dlat;
*lon2 = lon1 + dlon;
}
```