Baub
Baub

Reputation: 5044

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.

Upvotes: 4

Views: 5066

Answers (2)

Mike Gledhill
Mike Gledhill

Reputation: 29161

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 (?)

Upvotes: 2

nambi
nambi

Reputation: 547

This will work

NSArray *pointsArray = [mapView overlays];

[mapView removeOverlays:pointsArray];

Upvotes: 10

Related Questions