Google Directions 有一个 API 来解决 Traveling Salesman Problem --计算一组点的最短路线--但要收费。在 Apple 世界中,Polyline 和 MKRoute 似乎很有前途,但我在文档中找不到任何内容表明它们支持两个以上的点——开始和目标。有没有人在使用 MapKit 和/或 Core Location 时遇到过 TSP 问题?似乎可以使用类似的方法计算节点之间所有边的时间距离:
request.source = startLocation
request.destination = destLocation
request.requestsAlternateRoutes = true
request.transportType = .automobile
let directions = MKDirections(request: request)
directions.calculate { (directions, error) in
if var routeResponse = directions?.routes {
routeResponse.sort(by: {$0.expectedTravelTime <
$1.expectedTravelTime})
let quickestRouteForSegment: MKRoute = routeResponse[0]
completion(quickestRouteForSegment.expectedTravelTime)
}
}
}
并手动开发一种算法来尝试各种可能性并选择最快的算法。但这很快就会变得复杂并且需要很多请求。只是想知道是否有人发现了一种更复杂的方法来处理它。
最佳答案
您将无法通过使用 Mapkit 实现您想要的,因为您将需要大量请求并且 Apple 会限制您的应用程序。坚持使用 Google 或 Mapbox,它们具有用于 STP 的矩阵 API,而 Mapkit 没有。
关于IOS Mapkit or Core Location解决旅行商问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53824104/