Add overlays
myPolygon=[MKPolygon polygonWithCoordinates:points count:numberOfPoints];
[self.mapView addOverlay:myPolygon];
remove overlay
[self.mapView removeOverlay:myPolygon];
Thanks
When you call removeOverlays:, the map view will release the MKOverlay and MKOverlayView objects.
You hold your own references to these in myPolygon.
if (myPolygon != nil) {
[myPolygon release]; // <-- remove this
myPolygon = nil;
}
if (myPolygon != nil) {
[myPolygon release]; // <-- remove this
myPolygon = nil;
}
OR
for (id<MKOverlay> overlayToRemove in mapView.overlays)
{
if ([myPolygon isKindOfClass:[OverlayClassToRemove class]])
{
[mapView removeOverlay:myPolygon];
}
}