3

我使用此代码设置带有位置字符串的标签

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

locationLabel.text = locationString;

从地标获得通道、子通道、邮政编码、地方、国家代码的地方。

现在,我想根据当前的语言环境来可视化这个字符串。我是否为我感兴趣的每个语言环境指定了一个字符串格式,或者有更简单的方法来获取它?

谢谢,弗兰

4

2 回答 2

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*

            }
于 2012-10-26T08:54:37.207 回答
0

地标对象的 addressDictionary 属性应该部分解决其 FormattedAddressLines 数组的问题。

于 2010-11-27T13:01:57.980 回答