我有一条包含多个点(超过 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/