从GoogleMaps iOS Swift移除行进折线

问题描述 投票:0回答:1

我正在尝试从Google地图中删除已旅行的折线,但在互联网上找不到任何合适的解决方案。我以此绘制了折线,

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

这里polyline是一条GMSPolyline,我希望在用户通过其路径时将其删除。

swift google-polyline gmsmapview google-maps-direction-api
1个回答
0
投票

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

self.polyline?.map = nil

或者,您也可以通过调用GMSMapView clear方法来删除所有折线或形状。例如:

mapView.clear()

我希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.