IPhone: Calculate Walking Distance Using GPS

I want to calculate the distance users close while walking using GPS. For example, the user removes the start button and starts walking or running, than when he does, he stops. What will be the minimum distance that the user has to travel to get different long armor?

How can we do this in the IPhone, since we take Lat, long after every 0.3 seconds than in the last, we have a list of points?

+3


source to share


1 answer


You can do this by calculating the distance between two points (latitude, longitude):

(I haven't tested it):

-(double)distanceBetweenCoordinate:(CLLocationCoordinate2D)c1 andCoordinate:(CLLocationCoordinate2D)c2 {
    double long1 = degreesToRadians(c1.longitude);
    double lat1 = degreesToRadians(90 - c1.latitude);

    double long2 = degreesToRadians(c2.longitude);
    double lat2 = degreesToRadians(90 - c2.latitude);

    double gamma = fabs(long1 - long2);
    if (gamma > M_PI) {
        gamma = 2 * M_PI - gamma;
    }    

    double result = cos(lat2) * cos(lat1) + sin(lat2) * sin(lat1) * cos(gamma);
    return acos(result) * 6366.1977; // Kilometers
};

CGFloat degreesToRadians(CGFloat degrees) {
    return degrees * M_PI / 180;
};

      



UPDATE: Use distanceFromLocation. Calculating the distance between two points instead of

+3


source







All Articles