Remove all GMSMarker from GMSMapView?
Asked Answered
P

6

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?

Piscator answered 22/11, 2013 at 11:56 Comment(0)
H
43

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

Update:

Swift:

mapView.clear()
Hereof answered 5/12, 2013 at 10:21 Comment(0)
G
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!

Governorship answered 25/11, 2013 at 2:8 Comment(1)
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?Solano
H
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.

Hedjaz answered 13/1, 2015 at 16:15 Comment(0)
M
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.

Meteoroid answered 24/2, 2020 at 8:52 Comment(0)
M
1

Swift 4.x

self.mapView.clear()
Millisecond answered 2/1, 2019 at 14:8 Comment(0)
W
0

Try.....

[self.MapView clear];
Wiener answered 6/2, 2017 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.