0

I am calculating total number of feet climbed when user walking. I am using below core-location delegate method.

I declared oldelevation,newelevation and Totalelevation as int.

First Time I am taking Current spot Elevation to oldelevation.

- (void)locationUpdate:(CLLocation *)location
{
   newelevation =[location altitude]; //  Present Elevation

   if (newelevation > oldelevation) {

        TotalElevation = TotalElevation + newelevation - oldelevation;

       }

   oldelevation=newelevation;// Storing current elevation in old elevation.

}

Finally At the end of walk I multiplied Totalelevation with 3.28084 to get total number of feet climbed.

I am comparing my results with Runtastic Application.

I walked 0.40 Miles, Where Runtastic is 16 feet and my app total number of feet climbed is 208 feet.

I referred the following links but those are not giving accurate results.

Calculating Cumulative elevation gain give me wierd results

How to calculate elevation like in runkeeper application

iPhone Core Location: Calculate total elevation loss/gain

Community
  • 1
  • 1
Suresh
  • 1,015
  • 9
  • 16
  • Are you trying to calculate total number of feet climbed during the walk, or the gain in elevation from the beginning of the walk to the end? – Carl Veazey Nov 06 '13 at 15:24
  • @CarlVeazey is there any difference in total number of feet climbed and gain in elevation.could you help me please. – Suresh Nov 06 '13 at 15:30
  • if you walk up a hundred foot hill and back down, you'll have climbed 100 feet and gained 0 feet in elevation, right? – Carl Veazey Nov 06 '13 at 15:34
  • @CarlVeazey Yes you are right. I edited my question I want total number of feet climbed. – Suresh Nov 07 '13 at 05:36

1 Answers1

1

You should always evaluate the the altitude accuracy before doing calculation. the property verticalAccuracy returns negative if the altitude is invalid

if (currentLocation.verticalAccuracy >= 0 && previewsLocation.verticalAccuracy >=0) {
   if (currentLocation.altitude > previewsLocation.altitude) {
      TotalElevation = TotalElevation + currentLocation.altitude - previewsLocation.altitude;
   }
}
Simon
  • 17,223
  • 1
  • 19
  • 23