2

I am try to remove travelled polyline from google maps but can't find any proper solution on internet. I've drawn polyline by this,

let origin = "\(24.96487181552221),\(67.06045475052892)" //add worker lat long here
            let destination = "\(24.96485719),\(67.06699558)" //add job(customer) lat long here
            let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving&key=[Google-API-Key]"

            Alamofire.request(url).responseJSON { response in
                do{
                    let json = try JSON(data: response.data!)
                    let routes = json["routes"].arrayValue
                    for route in routes
                    {
                        let routeOverviewPolyline = route["overview_polyline"].dictionary
                        let points = routeOverviewPolyline?["points"]?.stringValue
                        self.path = GMSPath.init(fromEncodedPath: points!)

                        self.polyline = GMSPolyline(path: self.path)
                        self.polyline?.strokeColor = UIColor(hexString: "19C90E")
                        self.polyline?.strokeWidth = 3.0
                        self.polyline?.map = self.mapView

                    }
                }
                catch let error {
                    print(error)
                }
            }

here polyline is a GMSPolyline which i want to remove as user travel through it's path.

1 Answers1

1

As per the GMSPolyline documentation, you can remove the polyline from the map by setting the GMSPolyline map property to nil. For example:

self.polyline?.map = nil

Alternatively, you can also remove all polylines or shapes by calling the GMSMapView clear method. For example:

mapView.clear()

I hope this helps!

jabamataro
  • 1,154
  • 7
  • 13