You need to create your own class derived from MKMapView. This class must implement the MKMapViewDelegate protocol.
Then you need to follow 2 steps: create an annotation object and create a view for this annotation.
Create annotation:
Somewhere in your code, depends on your needs:
let annotation = MKPointAnnotation() annotation.setCoordinate(location) // your location here annotation.title = "My Title" annotation.subtitle = "My Subtitle" self.mapView.addAnnotation(annotation)
Create annotation view
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { if annotation is MKPointAnnotation { let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin") pinAnnotationView.pinColor = .Purple pinAnnotationView.draggable = true pinAnnotationView.canShowCallout = true pinAnnotationView.animatesDrop = true return pinAnnotationView } return nil }
source share