从当前位置移动时,我试图绘制路线。我在动态绘制路线时面临一个大问题,请帮助我解决它。我需要Swift IOS中的解决方案 我还需要一种方法来保存“跟踪的路径”,然后以哪种格式将其发送到服务器?
@objc func startRecording(){ self.mapView.clear()
// Initialize the locations list
self.locations = [CLLocation]()
// Set Tracking
self.locationManager.delegate = self
self.locationManager.requestAlwaysAuthorization()
self.mapView.isMyLocationEnabled = true
locationManager.distanceFilter = 100
locationManager.requestWhenInUseAuthorization()
mapView.settings.compassButton = true
locationManager.startUpdatingLocation()
mapView.settings.myLocationButton = true
// Start location manager
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.startUpdatingLocation()
// Initialize path
self.path = GMSMutablePath()
mapView.layer.borderWidth = 2
mapView.layer.borderColor = UIColor(red: 165/255, green: 10/255, blue: 42/255, alpha: 1.0).cgColor
}
// MARK: - Polyline and Screen Position Updaters
func updateOverlay(currentPosition: CLLocation) {
self.path.add(currentPosition.coordinate)
self.polyline.path = self.path
}
func updateMapFrame(newLocation: CLLocation, zoom: Float) {
let camera = GMSCameraPosition.camera(withTarget: newLocation.coordinate, zoom: zoom)
self.mapView.animate(to: camera)
}
func initializePolylineAnnotation() {
self.polyline.strokeColor = UIColor.blue
self.polyline.strokeWidth = 5.0
self.polyline.map = self.mapView
}
// MARK: - Map View Editor
func updateCurrentPositionMarker(currentLocation: CLLocation) {
self.currentPositionMarker.map = nil
self.currentPositionMarker = GMSMarker(position: currentLocation.coordinate)
self.currentPositionMarker.icon = GMSMarker.markerImage(with: UIColor.cyan)
self.currentPositionMarker.map = self.mapView
}