Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add iOS 10 default annotation/pin?

I have a MapView in my app. And user can add an annotaion/pin to that MapView. I works fine but I would like to know if it is possible to add new annotation design.

This is the new pin:

enter image description here

This is what my map shows:

enter image description here

This is my annotation code:

let annotaion = MKPointAnnotation()

this line adds my annotation to map:

self.myMap.addAnnotation(self.annotaion)

Thank you.

like image 568
0ndre_ Avatar asked Oct 21 '16 15:10

0ndre_


1 Answers

I believe @0ndre_ was looking for the default image, not to bring in his own custom image. The answer by @Franco_Meloni was incomplete. Here is how I got it to work.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

        let pin = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: nil)
        pin.canShowCallout = true

        let button = UIButton(type: .detailDisclosure)
        pin.rightCalloutAccessoryView = button

        if annotation.isEqual(mapView.userLocation) {
            return nil
        }
        return pin
    }

The key is using MKMarkerAnnotationView to get the bigger marker. If you use MKPinAnnotationView you will see the smaller one appear.

like image 160
Eric Duffett Avatar answered Nov 04 '22 03:11

Eric Duffett