<pre>
- (CLPlacemark*)getStartplacemark
- {
- //先创建一个semaphore
- dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
- dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
__block CLPlacemark* start;
[self.geoCoder geocodeAddressString:_SourceText.text completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *startPlaceMark = [placemarks firstObject];
start = startPlaceMark;
//发出已完成的信号
dispatch_semaphore_signal(semaphore);
}];
//等待执行,不会占用资源
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return start;
- }
</pre>