如何在选择新地图后从地图中删除注释?
所以,假设我在X和Y坐标上选择了引脚,并希望将此引脚移动到另一个地方而不添加新引脚。
同样简单的map.RemoveAnnotations();
不起作用。
以下是依赖于它的代码:
map = new MKMapView(new CGRect(0, 74 + point * 13, UIScreen.MainScreen.Bounds.Width, (UIScreen.MainScreen.Bounds.Height - (74 + point * 20))));
map.UserInteractionEnabled = true;
map.ZoomEnabled = true;
map.ScrollEnabled = true;
map.MapType = MKMapType.Standard;
map.ShowsUserLocation = true;
var longTap = new UILongPressGestureRecognizer() { };
longTap.AddTarget(() => AddPin(longTap, slider.Value));
longTap.MinimumPressDuration = 2.0;
map.AddGestureRecognizer(longTap);
map.GetViewForAnnotation += (mapView, annotation) =>
{
anView = new MKAnnotationView(annotation, Resources.kClusterAnnotationId);
anView.ClipsToBounds = true;
anView.CanShowCallout = false;
anView.Image = UIImage.FromFile("Icons/customMapPin.png");
return anView;
};
private void AddPin(UILongPressGestureRecognizer longTap, float value)
{
if (ifPointExist == false)
{
ifPointExist = true;
touchPoint = longTap.LocationInView(map);
pinMapCords = this.map.ConvertPoint(touchPoint, map);
CLLocation loc = new CLLocation(pinMapCords.Latitude, pinMapCords.Longitude);
map.AddAnnotations(new MKPointAnnotation()
{
Coordinate = new CLLocationCoordinate2D(pinMapCords.Latitude, pinMapCords.Longitude)
});
CLGeocoder geocoder = new CLGeocoder();
geocoder.ReverseGeocodeLocation(loc, (CLPlacemark[] placemarks, NSError error) =>
{
str = placemarks[0].AddressDictionary;
str.ToString();
});
AddCircle(value);
MKCoordinateSpan span = new MKCoordinateSpan(0.10, 0.10);
var coords = new CLLocationCoordinate2D(pinMapCords.Latitude, pinMapCords.Longitude);
map.Region = new MKCoordinateRegion(coords, span);
ifPointExist = false;
}
}
提前致谢