15

I am trying to display all possible routes between points A and B in my Swift app (iOS 8+ target). I allow the user to select any one of the possible routes in my app. Next, I would like the user to be able to navigate the selected route (MKRoute) in Apple Maps app, using

var fullRouteResponse:MKDirectionsResponse? //This variable has MKRoute information

@IBAction func openInAppleMaps(sender: AnyObject)
{
    let placemark = MKPlacemark(coordinate: destinationCoordinate!, addressDictionary: nil)

    mapItem = MKMapItem(placemark: placemark)

    mapItem.openInMapsWithLaunchOptions(
        [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
        MKLaunchOptionsMapTypeKey: MKMapType.Standard.rawValue,
        MKLaunchOptionsShowsTrafficKey: true ])

}

This opens up the Maps app fine, but I'm unable to figure out how to pass the specific selected MKRoute information so that the user doesn't have to re-select from all possible routes in Apple maps app.

I'm not sure if this is even possible, so any pointers would really help. Thanks!

sh4k
  • 306
  • 2
  • 5
  • Similar: [question](http://stackoverflow.com/questions/12658826/open-apple-maps-and-start-route-from-current-location-to-home-immediately-in-ios) – Raptor Jun 19 '15 at 06:17
  • @Raptor Still unanswered though :( I am able to open the maps app and route to the destination(Maps app asks me which route to choose). It doesn't take into consideration the fact that I have already selected a specific route in my app. I'm unable to pass that information to the maps app. – sh4k Jun 19 '15 at 11:29
  • Have you ever solved it? – zaitsman Feb 15 '19 at 01:11
  • Nope, haven't figured out – sh4k Feb 16 '19 at 02:14

2 Answers2

5

In documentation do not says that it is possible to pass pre configured path to native Maps app. So it is impossible to do what you want.

If here is undocumented way to achieve it I would like to know.

Ramis
  • 13,985
  • 7
  • 81
  • 100
2

Yes, you can do it using MapLink:

According to MapLink Documentation, you easily can do it filling the 'saddr' and 'daddr' parameters. Like this:

if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"http://maps.apple.com")!)) {
      UIApplication.sharedApplication().openURL(NSURL(string:
        "http://maps.apple.com:/?saddr=\(YOUR_SOURCE_LATITUDE),\(YOUR_SOURCE_LONGITUDE)&daddr=\(YOUR_DESTINATION_LATITUDE),\(YOUR_DESTINATION_LONGITUDE)&dirflg=d")!)

    }
Allan Scofield
  • 1,884
  • 18
  • 14