Open Apple Maps app with specific MKRoute information

940 views Asked by At

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!

2

There are 2 answers

1
Ramis On

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.

1
Allan Scofield On

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")!)

    }