How to launch Maps app and start navigation

Viewed 4067

In my iOS app I have latitude and longitude (CLLocationCoordinate2D) of a place the user would like to reach. I want than, when the relative button is pressed, that Maps application is launched and that street navigation to that place is started too. How can I achieve that? My code up to now is:

@IBAction func launchMapsApp(sender:UIButton) {
    if (sender == self.navButton) {

        let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: self.currentCoordinates, addressDictionary: nil))

        mapItem.name = ""

        //You could also choose: MKLaunchOptionsDirectionsModeWalking
        let launchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsShowsTrafficKey: true]

        mapItem.openInMapsWithLaunchOptions(launchOptions as? [String : AnyObject])
    }

}

But with this the Maps app is simply launched and I simply see a map of my state (Italy) and nothing more happens. Maybe, because I have run in only in simulator? Thanks to all

2 Answers
Related