ios - 如何删除 Traveled Polyline Google Maps SDK IOS
问题描述
我只想删除用户在路线上通过的折线
这些方法用于绘制运行平稳的折线
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 并想知道是否有人可以告诉我它是否可能以及如何?
解决方案
我正在回答我自己的问题 我解决了这个问题 在另一个帖子上查看我的答案
推荐阅读
- go - 使用 gRPC 状态包中的 WithDetails() 传递自定义原型消息
- android - 找不到资源 xml/opener_paths(又名 io.ionic.starter:xml/opener_paths)
- c++ - 使用 STL 在 C++ 中计算沿某个轴的多维向量的均值和标准差
- node.js - 如何更改 node.js 中 process.env.PORT 的值?(解决了)
- angular - 构造函数:类型 'void' 不可分配给类型 'any[]'
- android - 使用长短名称在 Android 中搜索应用
- python - 在 Python 中重现 MATLAB 的 imgaborfilt
- xamarin.forms - Xamarin.Forms:从代码中覆盖第 6 行网格的高度
- html - 打破表格单元格内没有空格的长文本
- php - Guzzle HTTP 客户端比 Symfony HTTP 客户端慢