Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert MKPlaceMark addressDictionary string encoded

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.

like image 513
Tue Nguyen Avatar asked Dec 01 '22 03:12

Tue Nguyen


2 Answers

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+

like image 195
Richard Groves Avatar answered Dec 07 '22 00:12

Richard Groves


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]);
like image 35
tarek1985 Avatar answered Dec 07 '22 01:12

tarek1985