I'm working on a GPS program that takes the current location and compares it to the destination location and returns the distance in miles if it's more than 1 mile and feet if it's less than a mile. The program works fine till I get less than 4,000 feet from the destination. At that point it returns that I'm at the destination. I'm using the tinygps and using the f_get_position command all which works fine. Just for some reason when the difference between the two numbers is small enough the program rounds it to 0.
I'm not concerned about being extremely accurate from a distance (just enough to know that you're getting closer to the destination) so I'm just using a simple Pathagoren theorem to figure the distance.
all variables are declared as float and destLat and destLon are just a random point within a mile of current location for testing.
what do i need to do to be able to get it to where i can find the distance to when I'm within say 20ft
while (nss.available())
{
int c = nss.read();
if (gps.encode(c))
{
gps.f_get_position(&lat, &lon);
//Calculates the distance between the two points
if (destLat > lat)
{
deltaLat = destLat - lat;
}
else
{
deltaLat = lat - destLat;
}
int deg, mins;
float temp;
deg = deltaLat/1;
temp = deltaLat -deg;
mins = temp*60.00;
//Convert from degs to miles.
deltaLat = (deg*69.00)+(mins*1.15);
if (destLon > lon)
{
deltaLon = destLon - (0-lon);
}
else
{
deltaLon = (0-lon) - destLon;
}
deg = deltaLon/1;
temp = deltaLon -deg;
mins = temp*60.00;
//Convert from Degs to miles
deltaLon = (deg*53.00)+(mins*.88);
float temp1, temp2;
temp1 = sq(deltaLat);
temp2 = sq(deltaLon);
hyp = sqrt(temp1 + temp2);
feet = hyp*5280;
}
}