Locale from CLPlacemark

312 views Asked by At

I try to get the ISO Country Code locale like "en_US" from a CLPlacemark Object. When i do a NSLog on the object, I get a lot of text including this:

address =                         {
                        "localized_address" =                             (
                                                            {
                                address =                                     {
                                    formattedAddressLine =                                         (
                                        "Piccadilly Circus",
                                        "Coventry Street",
                                        London,
                                        W1J,
                                        England
                                    );
                                    structuredAddress =                                         {
                                        administrativeArea = England;
                                        areaOfInterest =                                             (
                                            "Piccadilly Circus",
                                            "Great Britain"
                                        );
                                        country = "United Kingdom";
                                        countryCode = GB;
                                        dependentLocality =                                             (
                                            Mayfair
                                        );
                                        fullThoroughfare = "Coventry Street";
                                        geoId =                                             (
                                        );
                                        locality = London;
                                        postCode = W1J;
                                        subAdministrativeArea = London;
                                        subLocality = Mayfair;
                                        thoroughfare = "Coventry Street";
                                    };
                                };
                                locale = "en_US";

You can see in the last line exactly the information i need. But i've no clue how to access this information directly.

When I try to access the ISOcountryCode property of CLPlacemark i only get GB.

Thanks for your help Bernhard

1

There are 1 answers

1
Chris Loonam On BEST ANSWER

It's a bit hackish, but this is one way that you may be able to obtain the information

NSString *placemarkDescription = [yourPlacemark description];
NSString *regex = @"(locale)(\\s+)(=)(\\s+)("".*?"")(;)";
NSRange localeRange = [placemarkDescription rangeOfString:regex options:NSRegularExpressionSearch];
NSString *locale = [placemarkDescription substringWithRange:localeRange];

That regex is ugly and can probably be improved (I used http://txt2re.com), but this should be able to get the locale for you.