简体   繁体   English

从MapView删除MKAnnotation

[英]Remove MKAnnotation from MapView

Ok, I can add pin on my map by LongPress on any place of map. 好的,我可以通过LongPress在地图的任何位置上添加图钉。 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. 因此,我想下一步:当我单击我的图钉时,出现图钉的名称和带有叉的小按钮(在所有应用程序中都像要关闭的(X)一样),当用户单击此按钮(X)时,图钉必须删除。 Can I do this? 我可以这样做吗? Or maybe there is another simple way to delete pin for user without go to detailview about this pin? 或者,也许有另一种简单的方法可以为用户删除引脚,而无需转到有关此引脚的detailview?

  1. For remove all annotation use this code. 要删除所有注释,请使用此代码。

    [yourMapView removeAnnotation:yourMapView.annotations]; [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];
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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