Reputation: 222
i added overlay (MKOverlay) with custom drawings to the Mapview. The overlay showing fine and i can see the drawings. But when i remove that overlay its not removing perfectly some part of the drawing is still there. What is the reason? im using removeOverlay: for removing that overlay. Any help is appreciated..
Upvotes: 1
Views: 2581
Reputation: 19572
I kept getting multiple overlays on top of my MKCircle() after the location was updated. Here's the Swift 4 answer of @ErhanDemirci answer with my MKCircle being added to it afterwards. Step 2. is the Swift 4 version of the answer.
// 1. add the MKCircle
let circle = MKCircle(center: location.coordinate, radius: whateverRadius)
// 2. loop through the map view's overlays then remove it. The overlay is the MKCircle
for overlay in mapView.overlays {
mapView.remove(overlay)
}
// 3. add your the MKCircle to the mapView
mapView.add(circle)
Upvotes: 0
Reputation: 4209
you can delete all overlay in your map. it's working very well
add this function to yourviewController :
-(void)deleteMapOverlays
{
for (id<MKOverlay> overlay in mapView.overlays)
{
[self.mapView removeOverlay:overlay];
}
}
using :
[self deleteMapOverlays];
Upvotes: 2
Reputation: 3180
Don't know if you guys are still wondering about this, but the following works for me:
// assuming you have mapView and overlay defined somewhere
MKOverlayView *overlayView = [mapView viewForOverlay:overlay];
overlayView.hidden = YES;
[overlayView setNeedsDisplay];
[mapView removeOverlay:overlay];
Hope this helps!
Upvotes: 4