Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove MKMapView Overlay on Button Push

I have a MKMapView with a MKOverlay over it showing the location history of the user. On a button press, how can I discard this overlay and remove it from view?

I have tried [map removeOverlay:overlay]; but that doesn't work - it still shows.

like image 260
Baub Avatar asked Dec 17 '22 07:12

Baub


2 Answers

This will work

NSArray *pointsArray = [mapView overlays];

[mapView removeOverlays:pointsArray];
like image 182
nambi Avatar answered Dec 26 '22 22:12

nambi


Just to add that, for my iPad application, I needed to add an extra line to the solution shown above:

  NSArray *pointsArray = [self.mapView overlays];
  [self.mapView removeOverlays:pointsArray];

  self.mapOverlayView = nil;

Without setting mapOverlayView to nil, the "removeOverlays" call didn't seem to do much (?)

like image 32
Mike Gledhill Avatar answered Dec 26 '22 22:12

Mike Gledhill