0
我寫CLGecoder的代碼和代碼是問題與__block和CLGecoder在iOS中?
-(NSString *)GetCurrentAddress:(CLLocation *)Location
{
__block NSString *locatedaddress;
CLGeocoder *Gecoder=[[CLGeocoder alloc]init];
[Gecoder reverseGeocodeLocation: Location completionHandler:
^(NSArray *placemarks, NSError *error) {
//Get address
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"Placemark array: %@",placemark.addressDictionary);
//String to address
locatedaddress = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
//Print the location in the console
NSLog(@"Currently address is: %@",locatedaddress);
}];
return locatedaddress;
}
問題是completionHandler內locatedaddress有其價值,但外面是不? 任何人都可以幫助我嗎? 提前致謝。