【发布时间】:2016-12-19 06:58:02
【问题描述】:
我想使用 reverseGeocodeLocation 找出照片位置。我使用下面的函数
@interface GalleryPhotosViewController ()
{
CLPlacemark *placemark;
}
@end
-(NSString *)getLocation:(CLLocation *)locations{
CLGeocoder *geocoder = [CLGeocoder new];
[geocoder reverseGeocodeLocation:locations completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
placemark = [placemarks lastObject];
}];
return placemark.name;
}
调用该函数时我无法获得该名称,但在执行其他代码部分后我得到了该名称。我知道 reverseGeocodeLocation 有一个完成块,当执行到达它时它被移交给另一个线程。但是我需要在调用函数时获取该名称。我经历了很多解决方案,但无法解决我的问题。 我想在 currentLocation 中接收位置名称。
CLLocation *loc = asset.location;
NSString *currentLocation = [self getLocation:loc];
我应该在哪里更改我的代码。请帮忙。
【问题讨论】:
-
在
lacemark = [placemarks lastObject];行下方打印placemark.name(在完成处理程序中)并告诉我它是否会给出任何值! -
NSLog(@"addressDictionary %@", placemark.addressDictionary);你的坐标的打印地址。在 [geocoder reverseGeocodeLocation:locations completionHandler:^(NSArray
* _Nullable placemarks, NSError * _Nullable error) { placemark = [placemarks lastObject]; }]; -
对,但我想在每次调用方法时都使用块外的值。 @狮子
标签: ios objective-c clgeocoder