Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Apple Maps app with specific MKRoute information

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!

like image 361
sh4k Avatar asked Jun 19 '15 06:06

sh4k


2 Answers

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.

like image 195
Ramis Avatar answered Oct 18 '22 19:10

Ramis


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

    }
like image 35
Allan Scofield Avatar answered Oct 18 '22 19:10

Allan Scofield