import UIKit
import MapKit
class MapViewController: UIViewController{
lazy var geoCoder: CLGeocoder = {
return CLGeocoder()
}()
/**
开始导航
初始化一个我的位置MKMapItem,我要到的位置toMKPlacemark
*/
func StartNavigationBtn {
let currentLocation: MKMapItem = MKMapItem.mapItemForCurrentLocation()//我的位置
let toCoor:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 30.0, longitude: 30.0)
let toMKPlacemark: MKPlacemark = MKPlacemark.init(coordinate: toCoor, addressDictionary: nil)
let toLocation: MKMapItem = MKMapItem.init(placemark: toMKPlacemark)
toLocation.name = "去的地方";
let dic: [String : AnyObject] = [// 导航设置字典
MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,// 导航模式
MKLaunchOptionsMapTypeKey: MKMapType.Standard.rawValue,// 地图样式
MKLaunchOptionsShowsTrafficKey: true// 显示交通
]
MKMapItem .openMapsWithItems([currentLocation,toLocation], launchOptions: dic)
}
}
网友评论