A simple iOS application that demonstrates MapKit use by showing life events on a Map.
- Add the MapKit framework to the project
- Import MapKit and conform to the MKMapViewDelegate on the MapDetailViewController
- Change the
@import CoreLocation
to@import MapKit
in the Entry.h file - Add an enum for LifeEvents to the Person class, we will use this for creating MKAnnotations
- Update the cellSelectionStyle in the storyboard to Blue and add a segue to the MapDetailViewController
- Add an outlet for the MapView to the MapDetailViewController
- Set the MapDetailViewController as the delegate for the MapView
- Add a new PersonAnnotation class with a custom init method
- (PersonAnnotation *)initWithPerson:(Person *)person lifeEvent:(LifeEvent)event
. You will need a synthesized CLLocationCoordinate2D property called coordinate to conform to the MKAnnotation protocol. In the custom init method, set the coordinate property to the property matching the life event's location's coordinate. - Add an updateWithPerson method that will add the annotations for birthPlace and deathPlace to the map, run the method in the view did load with self.person (which will get set by the list view controller)
- Prepare the MapView with the
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
method. Use an MKPinAnnotationView, set the pin color, and set canShowCallout to YES.
- Add an outlet for the TableView on the list view controller
- Prepare for the segue by setting the Person property and running updateWithPerson on the MapDetailViewController when the user selects a cell (you will need to get the indexPath of the cell to update with the correct person)