Swift 从Google地图中删除移动的多段线

Swift 从Google地图中删除移动的多段线,swift,google-polyline,gmsmapview,google-directions-api,Swift,Google Polyline,Gmsmapview,Google Directions Api,我试图从谷歌地图中删除旅行多段线,但在互联网上找不到任何合适的解决方案。我用这个画了多段线 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 = "h

我试图从谷歌地图中删除旅行多段线,但在互联网上找不到任何合适的解决方案。我用这个画了多段线

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)
                }
            }

这里的多段线是一条GMSPolyline,当用户通过它的路径时,我想删除它。

根据
GMSPolyline
,您可以通过将
GMSPolyline
映射属性设置为
nil
从地图中删除多段线。例如:

self.polyline?.map = nil
mapView.clear()
或者,也可以通过调用
GMSMapView
clear
方法删除所有多段线或形状。例如:

self.polyline?.map = nil
mapView.clear()

我希望这有帮助

您错了,这将从地图中删除所有多段线和标记