If you wanted to track gain and loss separately, keep two cumulative member variables, netElevationLoss and netElevationGain, both initialized to 0.
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if(oldLocation == nil)
return;
double elevationChange = oldLocation.altitude - newLocation.altitude;
if (elevationChange < 0)
{
netElevationLoss += fabs(elevationChange);
}
else
{
netElevationGain += elevationChange;
}
}
You could also track total change using this method since
netElevationChange = netElevationGain - netElevationLoss
at any time.