ios-导航-跳转至系统app进行导航

import UIKit
import MapKit

class ViewController: UIViewController {

     var geoCoder = CLGeocoder()

    override func touchesBegan(_ touches: Set, with event: UIEvent?) {
        geoCoder.geocodeAddressString("北京") { (startCLPLS : [CLPlacemark]?,error : Error?) in
            self.geoCoder.geocodeAddressString("珠海") { (endCLPLS : [CLPlacemark]?,error : Error?) in
                self.beginNav(startCLPL: (startCLPLS?.first)!, endCLPL: (endCLPLS?.first)!)
            }
        }
    }

    
    /// 开始导航
    ///
    /// - Parameters:
    ///   - startCLPL: 开始地址
    ///   - endCLPL: 结束地址
    func beginNav(startCLPL : CLPlacemark,endCLPL : CLPlacemark) {
        
        let startItem = MKMapItem(placemark: MKPlacemark(placemark: startCLPL))
        let endItem = MKMapItem(placemark: MKPlacemark(placemark: endCLPL))
        
        let mapItems : [MKMapItem] = [startItem,endItem]
        
        let dict : [String : AnyObject] = [
            MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving as AnyObject,
            MKLaunchOptionsMapTypeKey:MKMapType.standard.rawValue as AnyObject,MKLaunchOptionsShowsTrafficKey:true as AnyObject]
        
        
        MKMapItem.openMaps(with: mapItems, launchOptions: dict)
        
    }

}

你可能感兴趣的:(ios-导航-跳转至系统app进行导航)