Reverse Geocoding and Localization

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

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

locationLabel.text = locationString;

where the mark is marked with the tag, subThoroughfare, postalCode, locality, countryCode.

Now I want to render this line according to the current locale. Have I set a string format for each region I'm interested in, or is there an easier way to get this?

Thanks Fran

+3
source share
2 answers

The addressDictionary property of the label object should partially solve the problem with its FormattedAddressLines array.

0
source

you can use the 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*

            }
+1
source

Source: https://habr.com/ru/post/1776901/


All Articles