Reputation: 4764
Google Directions has an api to solve the Traveling Salesman Problem--calculate the shortest route on a set of points--but charges for it. In the Apple world, Polyline and MKRoute seem promising but I can't find anything in the documentation to suggest they support more than two points--start and dest. Has anyone had any luck with the TSP problem using MapKit and/or Core Location? It seems one could calculate distance in time for all the edges between nodes using something like:
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)
}
}
}
and manually develop an algorithm that tries out the possibilities and selects the fastest. But this gets complicated quickly and requires many requests. Just wondering if anyone has discovered a more sophisticated way to approach it.
Upvotes: 0
Views: 355
Reputation: 1791
You will not be able to achieve what you want by using Mapkit as you will need a lot of requests and Apple will throttle your app. Stick with Google or Mapbox, they have matrix apis intended for the STP, Mapkit doesn't.
Upvotes: 1