Map get directions in "real time"

#Maps Hello, someone knows if there is a way to get directions in “real time” (turn right/ turn left etc) I tried to use MKDirectionsResponse but I’ll receive the whole path, do you have any suggestions or knows some framework?

Hi flexkid1,
Look up the Apple Developer Documentation for MKDirectionsResponse object here (Apple Developer Documentation). You are so close to the answer you were after.

The response object has an array of MKRoute that represents the instructions for the user to follow.
Each of the MKRoute object contains the geometry and other information including distance and travel time, etc (Apple Developer Documentation)

Each MKRoute has an array of MKRouteStep, which in turn contain the distinct portion of the steps involved in the direction (Apple Developer Documentation).

This MKRouteStep contains data like the instructions, notices, distance, transport type, etc (Apple Developer Documentation).

So to recap,

let steps = response.routes.first.steps
for eachStep in steps {
    print(eachStep.information, eachStep.distance, eachStep.transportType, eachStep.notice)
}

The step also has a polyline property that can be used to draw the overlay and it contains the co-ordinates, so if you want to display this in real time, you need to check the current coordinates and see in which step do the current co-ordinates fall and then display the information for that step.

Cheers,

Jayant

Thank you for the answer but I did resolve :slight_smile:

This topic was automatically closed after 166 days. New replies are no longer allowed.