我写了CLGecoder的代码,代码是
-(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;
}
问题出在address里面的completionHandler有值但是外面不是吗?任何人都可以帮助我吗?提前致谢。