4

I have the longitude and latitude from a location manager, now I am trying to reverse geo-code, to convert that information into address strings. I found the code below, that purportedly will do it, but I am getting a linker error. I think this means I am missing some framework or something. I was not able to find the answer. Can anyone help?

Error:

Apple Mach-O Linker Error
"_KABPersonAddressZIPKey", referenced from:

and so on for each of the strings that I am trying to generate.

 CLGeocoder *geocoder = [[CLGeocoder alloc] init];
 CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:latitude
                                                        longitude:longitude];
            [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error)

            {  
                       if (error) {
                           NSLog(@"Geocode failed with error: %@", error);
                           return;
                       }

                       if (placemarks && placemarks.count > 0)
                       {
                           CLPlacemark *placemark = placemarks[0];

                           NSDictionary *addressDictionary = placemark.addressDictionary;

                           NSString *address = [addressDictionary objectForKey:(NSString *)kABPersonAddressStreetKey];
                           NSString *city = [addressDictionary objectForKey:(NSString *)kABPersonAddressCityKey];
                           NSString *state = [addressDictionary objectForKey:(NSString *)kABPersonAddressStateKey];
                           NSString *zip = [addressDictionary  objectForKey:(NSString *)kABPersonAddressZIPKey];

                           NSLog(@"%@ %@ %@ %@", address,city, state, zip);

                       }
            }
    ];
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
OWolf
  • 5,012
  • 15
  • 58
  • 93

3 Answers3

7

Look up kABPersonAddressStreetKey in the documentation:

http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html

It says right at the top it's in the AddressBook framework. So you need to link to that.

matt
  • 515,959
  • 87
  • 875
  • 1,141
6

Add the following Framework to your Project, and Import it.

AddressBook.framework
AddressBookUI.framework

enter image description here

  • There is no need for the AdddressBookUI framework since only a few constants from the AddressBook framework are needed. – rmaddy Oct 29 '12 at 04:44
2

The code you posted is using some constants from the AddressBook framework. You need to add the AddressBook framework to your project target.

rmaddy
  • 314,917
  • 42
  • 532
  • 579