I want to find out photos location using reverseGeocodeLocation. I use the below function
@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;
}
I could not get that name when call the function but I get that after execution of other parts of code. I know that reverseGeocodeLocation has a completion block, it is handed off to another thread when execution reaches it. But I need to get that name when call the function. I go through many solutions but could not solve my problem. I want to receive location name in currentLocation.
CLLocation *loc = asset.location;
NSString *currentLocation = [self getLocation:loc];
Where should I change my code. Please help.
The method
reverseGeocodeLocation
of classCLGeocoder
runs asynchronously hence you will not get the location data as a return value from the called function. It uses the completion handler where the location data is returned and you can use that completion handler block to update the UI or any further processing of your location data.