I'm trying to deliver a user an ETA for walking if the walk is less than 15 mins, and for driving in other cases. I'd like to do this in a single MKDirections.Request() so that I don't have to recursively call the same function in its completion handler.
I can pass in an array for request.transportType, but I can't get both values back out, even though I can see them in the debugger.
func requestDirections(coordinates:CLLocationCoordinate2D, transitType:MKDirectionsTransportType, completion:@escaping(_ travelTime:Double, _ transportType:String)-> Void){
var travelTime:Double = -1.0
let directionRequest = MKDirections.Request()
directionRequest.source = MKMapItem.forCurrentLocation()
directionRequest.destination = MKMapItem(placemark: MKPlacemark(coordinate: coordinates))
directionRequest.transportType = [.automobile, .walking]
let directions = MKDirections(request: directionRequest)
directions.calculateETA(){(ETA,error) in
if(error == nil){
if(ETA.sortedETAs[0]>15){
completion(travelTime,"car")
}else{
completion(travelTime,"figure.walk")
}
}else{
completion(travelTime, "none")
}
}
}
Is it possible to do what I'm attempting?
From the debugger, if I right-click and Print Description of Sorted ETAs within the ETA return:
Printing description of ETA.some._sortedETAs:
<__NSArrayM 0x6040003b4dd0>(
<GEOETAResultByType: 0x60b0000a4d80> {
distance = 14530;
historicTravelTime = 786;
"static_travel_time" = 725;
status = "STATUS_SUCCESS";
transportType = AUTOMOBILE;
travelTimeBestEstimate = 784;
},
<GEOETAResultByType: 0x60b0000a4cd0> {
distance = 13111;
historicTravelTime = 10362;
"static_travel_time" = 10362;
status = "STATUS_SUCCESS";
transportType = WALKING;
travelTimeBestEstimate = 10362;
}