Search code examples
iosgoogle-mapsdictionarymapkitgoogle-maps-sdk-ios

ios - How to get turn-by-turn directions of an specific route?


I have a MKPolyline that I want MKMapkit to give me the turn-by-turn directions.

I know there is a way to get all the possible routes from point A to point B, but in my app I need to be able to provide turn-by-turn directions of route with certain restrictions:

  • Has to go through a certain street.
  • Avoid certain streets
  • Avoid lights
  • Take some detours, for sightseeing.

So is there a way to ask for trun-by-turn directions with restrictions?

Or can I ask turn-by-turn directions of a specific polyline that I know?


Solution

  • The Apple directions API (MKDirections / MKDirectionsRequest) can give you directions from point A to point B, but does not allow any other restrictions to be placed on the route.

    The Google Directions API (not part of the Google Maps SDK, but can be used through standard HTTP requests) does allow more restrictions, but not to the level you require.

    It does allow you to add up to 8 waypoints, so this would allow you to specific specific streets or detours in the directions request. It also allows you to avoid toll roads or motorways. It does not allow you to avoid certain streets or lights - I don't know of any directions API that has that level of detail.

    One other restriction of using Google Directions API is that you must show the results on a Google map.