-1
Add overlays
    myPolygon=[MKPolygon polygonWithCoordinates:points count:numberOfPoints];
    [self.mapView addOverlay:myPolygon];


remove overlay
    [self.mapView removeOverlay:myPolygon];

Thanks

jophab
  • 5,356
  • 14
  • 41
  • 60
bhavik
  • 1,673
  • 2
  • 14
  • 20

1 Answers1

0

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];
   }
}
Mitul Marsoniya
  • 5,272
  • 4
  • 33
  • 57