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

placemark オブジェクトの addressDictionary プロパティは、その FormattedAddressLines 配列の問題を部分的に解決する必要があります。

于 2010-11-27T13:01:57.980 に答える