I searched the internet for this solution. This is exactly the same as the google maps app on the iphone, where you search through your address book to find offers for your search.
What I have managed to do so far is to create a search bar and mapview, so when I look for the exact address, I get it on the map.
I want to make it easier for users who may have addresses stored in their address book to use them to search on a map.
I know that you need to use the search display controller and the address book, but I cannot find any examples of the search display controller other than the default table view.
that's what i still
EDIT.
I think no one knows. But it took me a couple of days to figure this out.
This solution is for everyone who wants to learn how to do it.
The key here is to get the address book data into an array, which you can use with the search display controller to filter it.
So here is the method I came up with to get the address book data:
- (void) getContactData { NSMutableDictionary *myAddressBook = [[NSMutableDictionary alloc] init]; self.names = [NSMutableArray array]; ABAddressBookRef addressBook = ABAddressBookCreate(); if (addressBook != nil){ NSLog(@"Successfully accessed the address book."); NSArray *allPeople = (__bridge_transfer NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook); NSString *address; NSUInteger peopleCounter = 0; for (peopleCounter = 0; peopleCounter < [allPeople count]; peopleCounter++){ ABRecordRef thisPerson = (__bridge ABRecordRef) [allPeople objectAtIndex:peopleCounter]; NSString *firstName = (__bridge_transfer NSString *) ABRecordCopyValue(thisPerson, kABPersonFirstNameProperty); NSString *lastName = (__bridge_transfer NSString *) ABRecordCopyValue(thisPerson, kABPersonLastNameProperty); NSString *company = (__bridge_transfer NSString *) ABRecordCopyValue(thisPerson, kABPersonOrganizationProperty); ABMutableMultiValueRef multiValue = ABRecordCopyValue(thisPerson, kABPersonAddressProperty); for(CFIndex i=0;i<ABMultiValueGetCount(multiValue);i++) { NSString* HomeLabel = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(multiValue, i); if([HomeLabel isEqualToString:@"_$!<Home>!$_"]) { CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multiValue, i); CFStringRef street = CFDictionaryGetValue(dict, kABPersonAddressStreetKey); CFStringRef city = CFDictionaryGetValue(dict, kABPersonAddressCityKey); CFStringRef state = CFDictionaryGetValue(dict, kABPersonAddressStateKey); CFStringRef zip = CFDictionaryGetValue(dict, kABPersonAddressZIPKey); CFRelease(dict); if (zip == nil) { address = [NSString stringWithFormat:@"%@, %@, %@ ", street, city, state]; }else { address = [NSString stringWithFormat:@"%@, %@, %@ , %@", street, city, state, zip]; } } if ([address length] != 0) {
Have fun coding!