I have a search bar in my application that the user can type an address into, and it will come up with the geocoded result. The result updates as the user types, according to the following code:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
...
if (self.geocoder.geocoding) [self.geocoder cancelGeocode];
[self.geocoder geocodeAddressString:searchText completionHandler:^(NSArray *placemarks, NSError *error) {
if (error != nil) {
NSLog(@"ERROR during geocode: %@", error.description);
return;
}
//update the view
}];
}
This works for the first few characters the user enters into the search field. However, after the user types more characters repeatedly, the geocoder starts giving the following error (which I know means that there was a problem with the network):
ERROR during geocode: Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"
The geocoder does not work again until the entire ViewController is reloaded. Why could this be happening, and what can I do to resolve it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…