0

我写了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有值但是外面不是吗?任何人都可以帮助我吗?提前致谢。

4

1 回答 1

3

地理编码器是异步的——根据定义,这意味着您无法立即获得结果。您必须使用完成处理程序对结果执行您想要执行的任何操作。

于 2012-12-18T22:46:05.827 回答