Skip to content

Instantly share code, notes, and snippets.

@JeremyXue77
Created November 5, 2018 10:57
Show Gist options
  • Save JeremyXue77/7148d39adbd9571e6984ac6d87d28bf0 to your computer and use it in GitHub Desktop.
Save JeremyXue77/7148d39adbd9571e6984ac6d87d28bf0 to your computer and use it in GitHub Desktop.
// 終點座標
let targetCoordinate = self.targetLocation.coordinate
// 初始化 MKPlacemark
let targetPlacemark = MKPlacemark(coordinate: targetCoordinate)
// 透過 targetPlacemark 初始化一個 MKMapItem
let targetItem = MKMapItem(placemark: targetPlacemark)
// 使用當前使用者當前座標初始化 MKMapItem
let userMapItem = MKMapItem.forCurrentLocation()
// 建立導航路線的起點及終點 MKMapItem
let routes = [userMapItem,targetItem]
// 我們可以透過 launchOptions 選擇我們的導航模式,例如:開車、走路等等...
MKMapItem.openMaps(with: routes, launchOptions: [MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment