convert MKPlaceMark addressDictionary string encoded

Tue Nguyen picture Tue Nguyen · Apr 9, 2011 · Viewed 7.7k times · Source

I working on a example to using MKReverseGeocoder to convert lat,long to address. But when i received data and try to get the result i received string from as below:

NSString *street = [geocoder.addressDictionary objectForKey:@"Street"];

I received a address like this: "Ng\U00f5 381 Nguy\U1ec5n Khang".

How can i convert it to unicode formatted string?

Thanks in advance.

Answer

Richard Groves picture Richard Groves · May 4, 2011

If you are getting the MKPlaceMark object back from the MKRevereseGeocoder delegate callback you can use the following to turn the placemark into a readable address:

NSLog(@"Address of placemark: %@", ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO));

You need to add the AddressBookUI framework to your project and

#import <AddressBookUI/AddressBookUI.h>

as well.

I'm not sure that the response is unicode, but it looks like it does a reasonable job of representing all the data in the placemark.

Untested, but

NSLog(@"Address of placemark: %@", [CNPostalAddressFormatter stringFromPostalAddress:placeMark.postalAddress style:CNPostalAddressFormatterStyleMailingAddress]);

And the framework needed is 'Contacts' so get that included with:

@import Contacts;

should be the new way of doing things in iOS11.0+