Convert MKPlaceMark addressDictionary string encoded

I am working on an example of using MKReverseGeocoder to convert lat, long address. But when I got the data and tried to get the result, I got the line as shown below:

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

I got an address like this: "Ng \ U00f5 381 Nguy \ U1ec5n Khang" .

How can I convert it to a unicode string?

Thanks in advance.

+4
source share
2 answers

If you are returning an MKPlaceMark object from an MKRevereseGeocoder delegate callback, you can use the following to turn the label into a readable address:

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

You need to add the AddressBookUI infrastructure to your project and

 #import <AddressBookUI/AddressBookUI.h> 

.

I'm not sure if the answer is unicode, but it looks like it does a reasonable job of presenting all the data in the label.

Not indexed, but

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

And in the frame you need "Contacts", so enable it with:

 @import Contacts; 

There must be a new way to do things in iOS11.0 +

+16
source

If you are returning an MKPlaceMark object from the MKPlaceMark delegate MKRevereseGeocoder , you can use the following to put the label in 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]); 
+3
source

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


All Articles