2010-11-25 98 views
3

我使用該代碼來設置的標籤帶,其中從一個標獲得的通途,subThoroughfare,POSTALCODE,局部性,COUNTRYCODE一個位置字符串反向地理編碼和本地化

locationString = [[NSString alloc] initWithFormat:@"%@%@ - %@ %@%@", 
        thoroughfare,subThoroughfare,postalCode, 
        locality,countryCode]; 

locationLabel.text = locationString; 

現在,我想根據當前的語言環境可視化該字符串。我是否爲每個我感興趣的區域指定一個字符串格式,或者有更簡單的方法來獲取它?

感謝, 弗蘭

+0

好的,謝謝。這個問題的任何想法? – Sefran2 2010-11-26 16:23:58

回答

0

地標對象的addressDictionary財產應在部分解決其FormattedAddressLines陣列的問題。

1

你可以用下面的函數

-(void) setLocation:(NSString *)latitude withLongitude:(NSString *)longitude { 
    CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
    CLLocation *location = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:    
    longitude doubleValue]]; 
     CLGeocodeCompletionHandler completionHandler =^(NSArray *placemarks, NSError *error){ 
       if (error){ 
         NSLog(@"error in fetching location <%@>",error); 
        return ; 
       } 
       if (placemarks && placemarks.count >0){ 
        CLPlacemark *mark = [placemarks objectAtIndex:0]; 
         NSString *addresstring = [[mark addressDictionary] objectForKey:@"FormattedAddressLines"] componentsJoinedByString:@","]; 
      *//fetched addressDictionary for key FormattedAddressLines* 

      }