ios - 如何在 iOS 的多点 Apple map 中显示路线

标签 ios mapkit apple-maps

我有一条包含多个点(超过 2 个)的路线,如何打开 Apple map 应用程序并显示它?

我知道可以显示两点之间的路线:

let mapItems = [MKMapItem(placemark: MKPlacemark(coordinate: coordinat1, addressDictionary: nil)),
                MKMapItem(placemark: MKPlacemark(coordinate: coordinat2, addressDictionary: nil))]
MKMapItem.openMaps(with: mapItems, launchOptions: [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving])

但它只支持两点。我也知道这可以通过使用这样的 url 使用 Google map 来实现:

https://www.google.com/maps/dir/<lat>,<lng>/<lat>,<lng>/.../.../

但我可以为 Apple Maps 找到类似的解决方案

编辑:因为我也可以像这样显示 Apple map :

UIApplication.shared.openURL(URL(string: "http://maps.apple.com/?daddr=\(coordinate.latitude),\(coordinate.longitude)&dirflg=d")!)

也许有某种方法可以传递更多坐标?

最佳答案

如 MKMapItem 文档所述:

If you specify the MKLaunchOptionsDirectionsModeKey option in the launchOptions dictionary, the mapItems array must have no more than two items in it. If the array contains one item, the Maps app generates directions from the user’s current location to the location specified by the map item. If the array contains two items, the Maps app generates directions from the location of the first item to the location of the second item in the array.

所以答案是否定的。

关于ios - 如何在 iOS 的多点 Apple map 中显示路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43371045/

相关文章:

ios - 根据地理编码地址更新 MapView,仅显示许多位置的一个图钉

ios - 释放放大后 map 会缩小

ios - Flutter 应用程序停留在物理 iPhone 的安装和启动步骤

cocoa - iOS MapKit - 每米点数

iphone - 在 iPhone 上的另一个 ViewController 上创建一个 View 弹出窗口

swift - "Compiler error: Invalid library file"在 Debug > Location 中模拟位置 - CoreLocation 和 MapKit

ios6 - 如何在我的应用程序 iOS 6 中获取行车路线

ios - 无法在 iPhone 内置 map 应用程序中显示路线

ios - 完成后添加函数 ((bool) -> void)

ios - 核心数据 : "Cannot delete object that was never inserted."