Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove GMSPolyline from GMSMapView

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];
}
like image 937
Gaurav Pandey Avatar asked Aug 03 '14 08:08

Gaurav Pandey


People also ask

How to remove polyline from google map swift?

Removing a polyline You can remove a polyline from the map by setting your GMSPolyline 's map property to nil .


3 Answers

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.

like image 77
Saxon Druce Avatar answered Nov 15 '22 20:11

Saxon Druce


You just need to set GMSPolyline map property to nil.

GMSPolyline *polyline;
polyline.map = nil;
like image 23
darshan Avatar answered Nov 15 '22 20:11

darshan


Just use below properly of Google Map:

mapView.clear()

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

like image 1
iVarun Avatar answered Nov 15 '22 18:11

iVarun