2012-12-18 30 views
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有其價值,但外面是不? 任何人都可以幫助我嗎? 提前致謝。

回答

3

地址解析器是異步的 - 根據定義意味着你不能馬上得到結果。您必須使用完成處理程序來執行您想要的結果。