19

I placed 100 GMSMarkers on GMSMapView. How to remove all the GMSMarkers?

In Google Sdk Version 1.6 for iOS.

Marker array(in GMSMapView (Overlays) file) which will be holding the GMSMarkers list is deprecated. By using this i was removing all GMSMarker from GMSMapView.

Is there any other way to remove all GMSMarker from GMSMapView in iOS?

gabriellanata
  • 3,946
  • 2
  • 21
  • 27
user3021529
  • 191
  • 1
  • 1
  • 3

6 Answers6

43

Use [mapView clear] to achieve required functionality. :-)

Update:

Swift:

mapView.clear()
Lal Krishna
  • 15,485
  • 6
  • 64
  • 84
Waleed Mahmood
  • 1,356
  • 12
  • 13
10

They deprecated those methods but you can use [mapView clear] to remove all overlays from the map. This includes all markers, polylines and groundOverlays.

Hope it helps!

gabriellanata
  • 3,946
  • 2
  • 21
  • 27
  • 2
    what if you just want to remove the markers and not the polylines and groundOverlays. is there a way to get a list of added markers? – Michael Feb 20 '14 at 19:49
5

Add all markers into NSMutableArray, as you add them to the map. Then when you need to remove them, iterate through the array and set each marker's .map property to nil.

misha2400
  • 195
  • 2
  • 9
2

Swift 5.x

If someone is looking to clear only a particular marker then you can use this:

marker.map = nil

If you want to remove everything from the map, like polyline, marker etc. then you can use

self.mapView.clear().

It will clear everything from the map.

Rob
  • 2,086
  • 18
  • 25
1

Swift 4.x

self.mapView.clear()
iHarshil
  • 739
  • 10
  • 22
0

Try.....

[self.MapView clear];
ArNo
  • 2,278
  • 1
  • 22
  • 19