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.
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+
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(@"The geocoder has returned: %@", [placemark addressDictionary]);
//all elements returned
//you can get some object like coutry ,code ;code country ...
NSLog(@"country ::::%@",[placemark country]);
NSLog(@"countrycode ::::%@",[placemark countryCode]);
NSLog(@"postalcode ::::%@",[placemark postalcode]);
NSLog(@"street::::%@",[placemark thoroughfare]);
NSLog(@"streetinfo::::%@",[placemark administrativeArea]);
NSLog(@"streeteersub ::::%@",[placemark subAdministrativeArea]);
来源:https://stackoverflow.com/questions/5604392/convert-mkplacemark-addressdictionary-string-encoded