how can I move the route mapped in mapkit swift 4

1

What happens if you mark the route and everything, but if I move either towards the direction, or against, the route is still there, and I want that if the road disappears along with me, or return to Appear. How can I achieve that?

annex code:

let directions = MKDirections (request: directionRequest)         directions.calculate (completionHandler: {             response, error in             guard let response = response else {                 if let error = error {                     print ("something went wrong (error)")                 }                 return             }

        let route = response.routes[0]
        self.mapkitView.add(route.polyline, level: .aboveRoads)
        let minutos = Int(route.expectedTravelTime / 60.0)

        print("distancia segun yo jeje->\(minutos)")
        let rekt = route.polyline.boundingMapRect
        self.mapkitView.setRegion(MKCoordinateRegionForMapRect(rekt), animated: true)
    })

    let annotation = MKPointAnnotation()
    annotation.coordinate = CLLocationCoordinate2DMake(latitud, longitud)
    annotation.title = nombre
    annotation.subtitle = "Aqui mero quieres llegar"
    mapkitView.addAnnotation(annotation)
}

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    let renderer = MKPolylineRenderer(overlay: overlay)
    renderer.strokeColor = #colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1)
    renderer.lineWidth = 5.0

    return renderer
}
    
asked by Jonathan Rivera 01.02.2018 в 05:01
source

1 answer

0

To delete the route you have set, you can use

self.mapView.removeOverlays(self.mapView.overlays)

and then you repaint it with the new data

    
answered by 13.05.2018 в 17:54