Search code examples
iosswiftgoogle-mapsswift3gmsmapview

Remove only polylines from GMSMapView without reference of them


How to remove only the polylines from my GMSMapView in Swift.

I don't use map.clear() because I have like 100 markers and groundOverlays that I don't want to delete and I do not have references of them.


Solution

  • Keep a record of the Polyline Array and set the .map property to nil for each polyline you want to remove.

    let poly = GSMPolyline()
    
    poly.map = mapView to show
    
    poly.map = nil to remove