【问题标题】:how to remove Traveled Polyline Google Maps SDK IOS如何删除 Traveled Polyline Google Maps SDK IOS
【发布时间】:2020-07-31 12:44:36
【问题描述】:

我只想删除用户在路线上通过的折线

这些方法用于绘制运行平稳的折线

func drawPolygon(from source: CLLocationCoordinate2D, to destination: CLLocationCoordinate2D){
googleMaps.isHidden = false
guard let url = URL(string: "https://maps.googleapis.com/maps/api/directions/json?origin=\(source.latitude),\(source.longitude)&destination=\(destination.latitude),\(destination.longitude)&sensor=false&mode=driving&key=KEYHERE") else {
    return
}

URLSession.shared.dataTask(with: url, completionHandler: {(data, response, error) in
    if(error != nil){
        print("error")
    }else{
        do{
            let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! [String : AnyObject]
            if json["status"] as! String == "OK"{
                let routes = json["routes"] as! [[String:AnyObject]]
                OperationQueue.main.addOperation({
                    for route in routes{
                        let routeOverviewPolyline = route["overview_polyline"] as! [String:String]
                        let points = routeOverviewPolyline["points"]
                        self.path = GMSPath.init(fromEncodedPath: points!)!
                        let polyline = GMSPolyline(path: self.path)
                        self.drawPath(polyline: polyline)
                    }
                })
            }
        }catch let error as NSError{
            print(error)
        }
    }
}).resume()
}

private func drawPath(polyline : GMSPolyline){

//DispatchQueue.main.async {
    
    polyline.strokeWidth = 6.0
    polyline.strokeColor = #colorLiteral(red: 0, green: 0.8465872407, blue: 0.7545004487, alpha: 1)
    polyline.map = self.googleMaps
    self.addMarker()
    // let bounds = GMSCoordinateBounds(path: path)
    // self.googleMaps.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 50.0))
    let bounds = GMSCoordinateBounds(coordinate: self.fromLoc!, coordinate: self.toLoc!)
    let update = GMSCameraUpdate.fit(bounds, with: UIEdgeInsets(top: 170, left: 30, bottom: 30, right: 30))
    self.googleMaps.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 20.0))
    self.googleMaps.animate(toZoom: 10)
    self.googleMaps.animate(toViewingAngle: 30)
    self.googleMaps!.moveCamera(update)
  self.timer = Timer.scheduledTimer(timeInterval: 0.003, target: self, selector: #selector(animatePolylinePath), userInfo: nil, repeats: true)
    
//}}

路线和折线运行良好。当用户通过路线上的线以获得更好的体验时,我正在考虑删除折线。我正在使用 Swift 5,想知道是否有人可以告诉我这是否可行以及如何实现?

【问题讨论】:

    标签: ios swift maps


    【解决方案1】:

    我正在回答我自己的问题 我解决了这个问题 看看我在另一个帖子上的回答

    How to remove the tracked polyline in Google map

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      相关资源
      最近更新 更多