Remove GMSPolyline from GMSMapView

10,731

Solution 1

You do need to do as you've said - store a reference to all of the polylines you've added (eg in an array), and then loop over them and set their map property to nil.

Solution 2

You just need to set GMSPolyline map property to nil.

GMSPolyline *polyline;
polyline.map = nil;

Solution 3

Just use below properly of Google Map:

mapView.clear()

Clears all markup that has been added to the map, including markers, polylines and ground

Share:
10,731
Gaurav Pandey
Author by

Gaurav Pandey

I’m a versatile, high-energy software engineer with 8 years of experience managing multiple aspects of the development process for multiple products mobile application, within the challenging time schedule.

Updated on June 20, 2022

Comments

  • Gaurav Pandey
    Gaurav Pandey almost 2 years

    I am using GoogleMap-IOS-1.8.1 SDK for displaying a map. I have to draw a GMSPolyline on the map. After a particular event I have to remove all GMSPolyline paths except for markers. I'm not sure of the best way to do that. The GoogleMaps documentation for iOS describe two methods to sue.

     1. [mapView_ clear];
     2. Set the GMSPolyline map property to nil
    

    Here the first approach removes all Markers and Overlays as well. This isn't exactly what I want. And for 2nd one it doesn't seem like the best method to save all of the GMSPolyline object references and then go back and set them all to nil.

    Is there a better way to do accomplish this task, or is this the only proper / correct way to do this?

    I was hoping for something like the following.

    for (GMSPolyline *polylineToremove  in mapView_.polyline)
    {
        [mapView_ removeOverlay:overlayToRemove];
    }