swift 在地图应用中获取路线

swift get directions in maps app

我有一个应用程序可以在多个地图视图中显示多个位置。我如何添加一个按钮,允许用户在他们的地图应用程序中打开这些位置之一并获取前往它的路线?

如果您有 MKPlaceMark,您可以使用 MKMapItem 并打开地图应用程序,位置为 launchOption:

var mapItem = MKMapItem(placemark: yourPlaceMark)

mapItem.name = "The way I want to go"

//You could also choose: MKLaunchOptionsDirectionsModeWalking
var launchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]

mapItem.openInMapsWithLaunchOptions(launchOptions)

Swift 3

mapItem.openInMaps(launchOptions: launchOptions)