【问题标题】:Removing travelled polyline from GoogleMaps iOS Swift从 GoogleMaps iOS Swift 中删除行进折线
【发布时间】:2020-05-19 11:18:06
【问题描述】:

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

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-directions-api


    【解决方案1】:

    根据GMSPolylinedocumentation,您可以通过将GMSPolyline 地图属性设置为nil 来从地图中移除折线。例如:

    self.polyline?.map = nil
    

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

    mapView.clear()
    

    我希望这会有所帮助!

    【讨论】:

    • 你错了,这将删除地图上的所有折线和标记
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    相关资源
    最近更新 更多