I'm developing an app that uses GPS position. For knowing position I get latitude and longitude.
I don't get position at regular intervals, but I want to know if user has moved. For that I store last position and current position (both latitude and longitude)
I was doing this:
if (latitudNew != latitudOld && longitudNew != longitudNew)
{
float R = 6378.137;
double dLat = ((latitudNew - latitudOld) * M_PI) / 180;
double dLong = ((longitudNew - longitudOld) * M_PI) / 180;
double a = sin(dLat/2) * sin(dLat/2) + cos((latitudOld*M_PI)/180) * cos((latitudNew*M_PI)/180) * sin(dLong/2) * sin(dLong/2);
double c = 2 * atan2(sqrt(a), sqrt(1-a));
double d = R * c;
}
Where distance is stored in d.
My problem is that it never get past the if condition, so I know I'm not comparing it correctly.
I can't use this solution, as I can have negative numbers (one or both or none).
Any ideas??