3

I am writing an app for iPhone iOS 3.0, where I want to use Map Kit and Address Book together. I have a database of places (restaurants, for example) with name, location, phone, address and some other data. I list them in a table view and when I choose some place I want to show Address Book Contact (with the help of ABUnknownPersonViewController), containing all information, so it is easy for user to add this contact to Address Book.

Now when I click on the address, the app switches me to Maps app. How can I catch this event to show it in my MKMapView (in my app internally)?

One more related question. Is there a way to implement "Direction from here", "Direction to here" buttons in standard Address Book Controller like in Maps app?

Marco
  • 6,692
  • 2
  • 27
  • 38
azia
  • 505
  • 1
  • 5
  • 11

2 Answers2

0

For the related question, direction from here and to here, you can use the URL http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f where you replace the %f's with latitude and longitude of start address (saddr) and destination address (daddr) of your likings. You can fetch the 'here' from the user location's latitude and longitude. This link will open in the default Maps application, but will show directions. HTH

drvdijk
  • 5,556
  • 2
  • 29
  • 48
  • Thank you for your answer, but I am asking about buttons(rows) in standard Address Book Controller(ABUnknownPersonViewController, for example). Like in Maps app(the way it shows an address after clicking accessory view). – azia Aug 05 '09 at 13:12
0

Intercept the default action in ABUnknownPersonViewController's delegate method to prevent switching to the Maps app:

// ABUnknownPersonViewControllerDelegate protocol conformance
- (BOOL)unknownPersonViewController:(ABUnknownPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    // Allow the default action to occur.
    BOOL shouldPerformDefaultAction = YES;

    // If address property was selected, do not switch to the Maps.app.
    if (property == kABPersonAddressProperty)
    {
        [self.navigationController popViewControllerAnimated:YES];

        // Do not perform the default action    
        shouldPerformDefaultAction = NO;

        // Show your MKMapView here
        // ....
    }

    return shouldPerformDefaultAction;
}
Marco
  • 6,692
  • 2
  • 27
  • 38