title: How to calculate the average altitude through gps location manager in iphone
body: <p>I want to calculate the maximum altitude, minimum altitude, and average altitude of the current location through <code>CLLocationManager</code>. I know how to calculate the altitude using the following code:</p>
  
  <pre><code>    #import &lt;UIKit/UIKit.h&gt;
      #import &lt;CoreLocation/CoreLocation.h&gt;
  
      @interface test : UIViewController &lt;CLLocationManagerDelegate&gt; {
          CLLocationManager   *locationManager;
  
          CLLocation  *startingPoint;
  
          IBOutlet    UILabel *altitudeLabel;
  
      }
      @property (retain, nonatomic) CLLocationManager *locationManager;
      @property (retain, nonatomic) CLLocation *startingPoint;
      @property (retain, nonatomic) UILabel *altitudeLabel;
      @end
      //this is my test.h class
  
  
  
  
      #import "test.h"
  
      @implementation test
      @synthesize locationManager;
      @synthesize startingPoint;
      @synthesize altitudeLabel;
  
  
      #pragma mark -
      - (void)viewDidLoad {
          self.locationManager = [[CLLocationManager alloc] init];
          [locationManager startUpdatingLocation];
          locationManager.delegate = self;
          locationManager.distanceFilter = kCLDistanceFilterNone; 
          locationManager.desiredAccuracy = kCLLocationAccuracyBest;
      }
      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
          // Return YES for supported orientations
          return (interfaceOrientation == UIInterfaceOrientationPortrait);
      }
  
      - (void)dealloc {
  
          [locationManager release];
          [startingPoint release];
          [altitudeLabel release];
  
          [super dealloc];
      }
      #pragma mark -
      #pragma mark CLLocationManagerDelegate Methods
      - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
  
          if (startingPoint == nil)
              self.startingPoint = newLocation;
  
  
          NSString *altitudeString = [[NSString alloc] initWithFormat:@"%gm", newLocation.altitude];
          altitudeLabel.text = altitudeString;
          [altitudeString release];
  
  
  
      }
  
      - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
  
          NSString *errorType = (error.code == kCLErrorDenied) ? @"Access Denied" : @"Unknown Error";
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error gettingg location from Core Location" message:errorType delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
          [alert show];
          [alert release];
  
      }
  
      @end
  </code></pre>
  
  <p>Through this I only get the altitude value, but I need to know how to calculate average altitude, minimum altitude, and maximum altitude. Does anyone know how to do this?</p>