美文网首页
ios-导航-跳转至系统app进行导航

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

作者: child_cool | 来源:发表于2017-04-05 14:15 被阅读0次
import UIKit
import MapKit

class ViewController: UIViewController {

     var geoCoder = CLGeocoder()

    override func touchesBegan(_ touches: Set<UITouch>, 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进行导航

      本文链接:https://www.haomeiwen.com/subject/myotattx.html