简体   繁体   中英

Remove MKAnnotation from MapView

Ok, I can add pin on my map by LongPress on any place of map. Now I need to delete pins. So I want next: when I click on my pin, appear the name of pin and a little button with cross ((X) like in all apps to close), when user will click this button (X) - pin must be deleted. Can I do this? Or maybe there is another simple way to delete pin for user without go to detailview about this pin?

  1. For remove all annotation use this code.

    [yourMapView removeAnnotation:yourMapView.annotations];

  2. For remove one annotation just implement logic For example...

    First remove all annotation and also remove your selected pin data from the array and after add this new array and add annotation..

// REMOVING ALL ANNOTATION
    for (id <MKAnnotation>  myAnnot in [objMapView annotations])
    {
        if (![myAnnot isKindOfClass:[MKUserLocation class]])
        {
            [objMapView removeAnnotation:myAnnot];
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM