Starting the Maps application in a location programming guide says:
If you prefer to display map information in the Maps application rather than in your own application, you can launch Maps programmatically using one of two methods:
On iOS 6 and later, use the MKMapItem object to open Maps.
In iOS 5 and earlier, create and open a specially formatted map URL, as described in Apple URL Link .
The preferred way to open the Maps application is to use the MKMapItem class. This class offers the openMapsWithItems:launchOptions: and openInMapsWithLaunchOptions: to open the application and display locations or directions.
For an example showing how to open the Maps application, see "Requesting the Maps Application to Display Routes."
So you should:
Make sure your view controller is delegate to your map view;
Write a viewForAnnotation that includes canShowCallout and includes a view of accessories accessories :
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { if ([annotation isKindOfClass:[MKUserLocation class]]) return nil; MKAnnotationView* annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyCustomAnnotation"]; annotationView.canShowCallout = YES; annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; return annotationView; }
Then write a calloutAccessoryControlTapped method that will open the cards as described above, based on which versions of iOS you support, for example, for iOS 6:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { id <MKAnnotation> annotation = view.annotation; CLLocationCoordinate2D coordinate = [annotation coordinate]; MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]; MKMapItem *mapitem = [[MKMapItem alloc] initWithPlacemark:placemark]; mapitem.name = annotation.title; [mapitem openInMapsWithLaunchOptions:nil]; }
I donβt know what additional geographic information you have in your KML, but you can probably fill out the addressDictionary as you like.
In answer to your question on how to use the addressDictionary parameter of the addressDictionary initializer MKPlacemark , initWithCoordinate , if you had NSString variables for street address , city , state , zip , etc., it would look like this:
NSDictionary *addressDictionary = @{(NSString *)kABPersonAddressStreetKey : street, (NSString *)kABPersonAddressCityKey : city, (NSString *)kABPersonAddressStateKey : state, (NSString *)kABPersonAddressZIPKey : zip};
To do this, you need to add the appropriate structure , AddressBook.framework to your project and import the title in your .m file:
#import <AddressBook/AddressBook.h>
The real question, however, was how to set the name for MKMapItem so that it would not appear as an "Unknown location" in the map application. This is as simple as setting the name property, perhaps just grabbing the title from your annotation :
mapitem.name = annotation.title;