【发布时间】:2020-06-07 20:39:18
【问题描述】:
我是地图技术的新手。 我正在使用 google apis 到 json 数据以使用折线获取地图上的路线。 我需要一些关于 polyline 的帮助。我想根据用户驾驶路线清除折线的路径。我尝试搜索许多解决方案,但无法为我工作。 我附上了相同的图片...
绘制折线的功能---
func drawPath(from polyStr: String){
print("inside Drawpath")
path = GMSPath(fromEncodedPath: polyStr)!
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 6
polyline.map = myMapView // Google MapView
polyline.strokeColor = UIColor(red: 0, green: 128/255, blue: 1, alpha: 1)
// let camera = GMSCameraUpdate.fit(GMSCoordinateBounds(coordinate: CLLocationCoordinate2D(latitude: Double(lat), longitude: Double(long)), coordinate: CLLocationCoordinate2D(latitude: Double(directionlat)!, longitude: Double(directionlat)!)))
let cameraUpdate = GMSCameraUpdate.fit(GMSCoordinateBounds(coordinate: CLLocationCoordinate2D(latitude: Double(lat), longitude: Double(long)), coordinate: CLLocationCoordinate2D(latitude: Double(directionlat)!, longitude: Double(directionlat)!)))
// self.timer = Timer.scheduledTimer(timeInterval: 0.003, target: self, selector: #selector(animatePolylinePath), userInfo: nil, repeats: true)
//myMapView.moveCamera(cameraUpdate)
let currentZoom = myMapView.camera.zoom
// myMapView.animate(toZoom: currentZoom - 1.4)
}
感谢任何帮助。 谢谢和问候
【问题讨论】:
-
您可以保存最后一个位置并使用 didUpdateLocations 位置监视新位置并获取用户最后一个位置,然后将其与保存的位置进行比较,然后如果它改变了绘制新的折线
-
谷歌地图有没有类似 didupdatelocation 的功能?
-
是的,更新位置是谷歌地图功能之一
-
也许它对你有用 -> stackoverflow.com/a/44471050/7512091
标签: swift xcode polyline gmsmapview