title: How to update location only when button is pressed
body: <p>How can I make my application update location only when a button is pressed?</p>
  
  <p>I have a button named "REFRESH". Everytime this button is pressed, I want to show my user their location. For example, <code>51 Bourke Street, Victoria</code>. </p>
  
  <p>However, I do not want to update my location regularly. I want to update its location only when the button is pressed, to save battery power.</p>
  
  <p>What do you think? Am I doing it correctly? </p>
  
  <p>I have these classes:</p>
  
  <ul>
  <li>VoteViewController.h and VoteViewController.m</li>
  <li>CoreLocationController.h and CoreLocationController.m</li>
  </ul>
  
  <p>This is what I have:</p>
  
  <p><code>VoteViewController.h</code> class
  <br/></p>
  
  <pre><code>@interface VoteViewController : UIViewController &lt;CoreLocationControllerDelegate&gt; 
  {
      CoreLocationController *coreController;
  }
  
  - (void)locationUpdate:(CLLocation *)location; 
  - (void)locationError:(NSError *)error;
  - (void)geoReverseAddress:(MKPlacemark *)placeMark;
  - (IBAction)refreshButtonPressed;
  </code></pre>
  
  <p><code>VoteViewController.m</code> class
  <br/></p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      coreController = [[CoreLocationController alloc] init];
      coreController.delegate = self;
  }
  
  - (IBAction)refreshButtonPressed
  {
      NSLog(@"Refresh Button pressed");
      label.text = [NSString stringWithString:@""];
      [coreController.locationManager startUpdatingLocation];
  }
  
  - (void)locationUpdate:(CLLocation *)location 
  {
      comments.text = [location description];
      [coreController.locationManager stopUpdatingLocation];
  }
  
  - (void)locationError:(NSError *)error 
  {
      comments.text = [error description];
      [coreController.locationManager stopUpdatingLocation];
  }
  
  - (void)geoReverseAddress:(MKPlacemark *)placeMark
  {
      label.text = [NSString stringWithFormat:@"%@ %@, %@", [placeMark subThoroughfare], 
  [placeMark thoroughfare], [placeMark locality]]; 
  }
  </code></pre>
  
  <p><code>CoreLocationController.h</code> class
  <br/></p>
  
  <pre><code>@protocol CoreLocationControllerDelegate &lt;NSObject&gt;
  
  @required
  - (void)locationUpdate:(CLLocation *)location;
  - (void)locationError:(NSError *)error;
  - (void)geoReverseAddress:(MKPlacemark *)placeMark;
  
  @end
  
  @interface CoreLocationController : NSObject &lt;CLLocationManagerDelegate, MKReverseGeocoderDelegate&gt;
  {
      CLLocationManager *locationManager;
      id delegate;
  
      MKReverseGeocoder *reverse;
  }
  
  @property(nonatomic, retain) CLLocationManager *locationManager;
  @property(nonatomic, retain) id delegate;
  @end
  </code></pre>
  
  <p><code>CoreLocationController.m</code> class
  <br/></p>
  
  <pre><code>-(id) init
  {
      self = [super init];
  
      if (self != nil)
      {
          self.locationManager = [[[CLLocationManager alloc] init] autorelease];
          self.locationManager.delegate = self;
          self.locationManager.distanceFilter = kCLHeadingFilterNone;
          self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
      }
      return self;
  }
  
  - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
  {
      NSLog(@"Update location");
      [self.delegate locationUpdate:newLocation];
  
      reverse = [[MKReverseGeocoder alloc] initWithCoordinate:[newLocation coordinate]];
      reverse.delegate = self;
      [reverse start];
  }
  
  - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
  {
      [self.delegate locationError:error];
  }
  
  - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
  {
      [self.delegate locationError:error];
      [reverse cancel];
      [reverse release];
  }
  
  - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
  {
      [self.delegate geoReverseAddress:placemark];
      [reverse cancel];
      [reverse release];
  }
  </code></pre>