0

当我选择一个新的目的地位置时,我想隐藏一个路线图。现在的问题是让我保留所有最古老的路线。这是我的代码的一部分,每次用户点击地图时都会绘制一条路线。

 override func viewDidLoad() {
        super.viewDidLoad()
        mapView.delegate = self
        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.tapped(_:)))
        mapView.addGestureRecognizer(tapGestureRecognizer)
    }

@objc func tapped (_ recognizer: UITapGestureRecognizer) {
        // Get point on screen
        let point = recognizer.location(in: mapView)

        // Convert point to NSValue
        let value = NSValue(cgPoint: point)

        // Get coordinates for point from screen
        let coordinates = mapView.geoCoordinates(fromScreenPoints: [value])
        // now handle the coordinates, as you wish
        endPointMP = SYGeoCoordinate(latitude: coordinates[0].latitude, longitude:coordinates[0].longitude)
        let markerEnd = SYMapMarker(coordinate: endPointMP!, image: UIImage(named: "Arrive")!)
        startPointMP = SYGeoCoordinate(latitude: SYPositioning.shared().lastKnownLocation?.coordinate?.latitude ?? 0, longitude:  SYPositioning.shared().lastKnownLocation?.coordinate?.longitude ?? 0)
        let markerStart = SYMapMarker(coordinate: startPointMP!, image: UIImage(named: "Depart")!)
        mapView.add(markerEnd)
        mapView.add(markerStart)
        computeRoute(from: startPointMP!, to: endPointMP!)
    }

func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate:
        SYGeoCoordinate) {
        let startWaypoint = SYWaypoint(position: fromCoordinate, type: .start, name: "Begin")
        let endWaypoint = SYWaypoint(position: toCoordinate, type: .end, name: "End")
        let routingOptions = SYRoutingOptions()
        routingOptions.transportMode = .unknown// For other options see SYTransportMode
        routingOptions.routingType = .economic// For other options see SYRoutingType
        routing.computeRoute(startWaypoint, to: endWaypoint, via: nil, with: routingOptions)
    }

此致

4

0 回答 0