title: Restrict reverse geolocating - kCLErrorDomain Code=2
body: <p>I am currently trying to write an iOS app that logs the states that a user has visited.</p>
  
  <p>The issue I am facing is that my <code>(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations</code> method is being called over and over again. I don't necessarily see this as an issue except in that method, I am calling another method that reverse geocodes the CLLocation object and gives the state name.</p>
  
  <p>The error I am getting is:</p>
  
  <pre><code>Geocode failed with error: Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"
  </code></pre>
  
  <p>I understand that I am reaching the limit on reverseGeoCoding over a certain timelimit, I am just not sure how to limit it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>CLLocation *currentLocation;
  
  - (void) getLocation
  {
      CLGeocoder *geocoder = [[CLGeocoder alloc] init];
      [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error)
       {
  
           if (error){
               NSLog(@"Geocode failed with error: %@", error);
               return;
  
           }
  
           if(placemarks &amp;&amp; placemarks.count &gt; 0)
           {
               CLPlacemark *placemark= [placemarks objectAtIndex:0];
               currentState = [NSString stringWithFormat:@"%@",[placemark administrativeArea]];
           }
  
           //Checks to see if the state exists in the textFile, if not it writes it to the file
           if(![newState checkIfStateExists:currentState])
           {
               [newState writeToFile:currentState];
           }
  
       }];
  }
  
  -(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
  {
      //just a thought, didn't work
      //if(![[locations lastObject] isEqual:currentLocation])
  
          currentLocation = [locations lastObject];
          [self getLocation];
  
  }
  
  -(void) initializeGPS
  {
      self.locationManager = [[CLLocationManager alloc] init];
      locationManager.delegate = self;
      locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
      locationManager.distanceFilter = kCLDistanceFilterNone;
      [locationManager startUpdatingLocation];
  }
  
  
  - (void) viewDidLoad
  {
      [self initializeGPS];
      [super viewDidLoad];
  
  }
  </code></pre>
  
  <p>This code works perfectly in the fact that it gets the location in GPS coordinates, translates it into a state name, and writes that state name to a file.</p>
  
  <p>It is just being called too many times, and I am unsure how to limit the number of times that <code>(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations</code>is called.</p>