我正在开发一个适用于IOS5的iPhone应用程序。我目前正在使用位于CoreLocation框架内的CLGeocoder类。我无法确定完成处理程序块是在地理编码结束后还是同时调用的。
我只知道完成处理程序块在主线程上运行。有人知道完成处理程序块是否在地理编码完成后运行,还是在地理编码器在另一个线程上执行时完成任务的代码?
我只知道完成处理程序块在主线程上运行。有人知道完成处理程序块是否在地理编码完成后运行,还是在地理编码器在另一个线程上执行时完成任务的代码?
@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