IOS5 CLGeocoder

I am developing an iPhone application for iOS5. I am currently using the CLGeocoder class located within CoreLocation. I cannot understand if the completion handler block is called at the end, after geocoding occurs or at the same time.

I only know that the completion handler block starts in the main thread. Does anyone know if the completion handler block is executed when geocoding is complete or is it the code to complete the task at hand while the geocoder is executing another thread?

+3
source share
2 answers

. , . - .

. , . , .

:

. . - .

, . , kCLErrorNetwork .

@interface MyGeocoderViewController ()

@property (nonatomic, strong) CLGeocoder *geocoder;

@end

@implementation MyGeocoderViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Create a geocoder and save it for later.
    self.geocoder = [[CLGeocoder alloc] init];
}
- (void)geocodeAddress:(NSString *)addressString
{
    // perform geocode
    [geocoder geocodeAddressString:addressString
        completionHandler:^(NSArray *placemarks, NSError *error) {

        if ((placemarks != nil) && (placemarks.count > 0)) {
            NSLog(@"Placemark: %@", [placemarks objectAtIndex:0]);
        }
        // Should also check for an error and display it
        else {
            UIAlertView *alert = [[UIAlertView alloc] init];
            alert.title = @"No places were found.";
            [alert addButtonWithTitle:@"OK"];
            [alert show];
        }
    }];
}

@end
+6

All Articles