'Is it possible to redraw a route on invalid turn | Swift
I am drawing a polyline between 2 points for the user to follow and execute the code in didUpdateLocations using location manager. Is there a way to trigger a redrawing of this polyline if the user makes an incorrect turn? Meaning if the users location goes of the route line - can I trigger a recalculation?
Essentially this is the logic behind the polyline:
directionRequest.transportType = .automobile
let directions = MKDirections(request: directionRequest)
directions.calculate { (response, error) in
guard let response = response else { return }
let route = response.routes.first
if let line = route?.polyline {
self.mapView.addOverlay(line, level: .aboveRoads)
DispatchQueue.main.asyncAfter(deadline: .now()) { [self] in
let distanceAway = String(format:"%.0f", route!.distance / 1609)
let minutesAway = route!.expectedTravelTime / 60
if let first = mapView.overlays.first {
//Other Actions
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
