开发者

reverse geocoding and localization

开发者 https://www.devze.com 2023-01-27 10:50 出处:网络
I use this code to set a label with a location string locationString = [[NSString alloc] initWithFormat:@\"%@%@ - %@ %@%@\",

I use this code to set a label with a location string

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

locationLabel.text = locationString;

where thoroughfare, subThoroughfare, postalCode, locality,countryCode are obtained from a placemark.

Now, I'd like to visualize this string accord开发者_运维问答ing the current locale. Have I specify a string format for each locale in which I'm interested or there is a simpler way to obtain this?

Thanks, Fran


you can use following function

-(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*

            }


The addressDictionary property of the placemark object should resolve in part the problem with its FormattedAddressLines array.

0

精彩评论

暂无评论...
验证码 换一张
取 消