I want to get the current location\'s address and set it to the annotation\'s title. But it didn\'t work. I think it\'s because of the block, but I don\'t know how to fix it. An
You are returning the address while modifying it inside an asynchronous block. You should move the return inside the block, or a create a protocol to handle passing this information back to the caller.
Change the block to this:
- (void)addrAtLocation:(CLLocation *)location{
[self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemark, NSError *error) {
CLPlacemark *topResult = [placemark objectAtIndex:0];
whereAmIAnnotation.addr = [NSString stringWithFormat:@"%@ %@ %@ %@", topResult.country, topResult.locality, topResult.subLocality, topResult.thoroughfare];
}];
}
Then make whereAmIAnnotation
a member variable. Do you understand WHY this fixes your issues?