Trying to get formatted address from AddressDictionary, that I got from CLGeocoder. Used following code with no result:
subtitle = [NSString stringWithString:[[addressDict objectForKey:@"FormattedAddressLines"]objectAtIndex:0]];
Also tried:
subtitle = [[[ABAddressBook sharedAddressBook] formattedAddressFromDictionary:placemark.addressDictionary] string];
but this code seems working on Mac OS X only.
Compiler asks about ABAdressBook, but I have both header files imported.
#import <AddressBook/ABAddressBook.h>
#import <AddressBook/AddressBook.h>
Swift 3 / Xcode 8 Helper Mehtod to get address from CLPlaceMark
Above is the swift version.
After doing some digging under iOS 6.1 I found out that the CLPlacemark address dictionary contains a pre-formatted address:
I couldn't yet find documentation about this, but it works for all the addresses that I tested.
As highlighted by Martyn Davis,
ABCreateStringWithAddressDictionary
is deprecated in iOS 9.You can use the functions below to convert the
addressDictionary
to the newerCNMutablePostalAddress
, then use theCNPostalAddressFormatter
to generate a localised string as long as you import theContacts
framework.Swift 3.x
Swift 2.x
The documentation for the
addressDictionary
property says:So add and import the
AddressBookUI
framework and try:I am using Swift 3 / XCode 8
ZYiOS's answer was nice and short but did not compile for me.
The question asks how to get from an existing Address Dictionary to a string address. This is what I did: