Hi Lindsey, Thank you this is amazing. I have a really dumb question!!! Where do you create the code making this a return trip?
Also, is there anyway to create a list of roads (as opposed to directions)?
Thank you
Thanks for a great and informative post. I have a question. I have been trying to figure out how to display a label similar to the time label, but for the overall distance of the route, but have been unsuccessful so far. Any ideas or pointers?
Hi Lindsey, Do you have any hints on how to convert the code to Swift 3.
I am getting one remaining error and don’t have the knowledge to fix it
The working Swift 2 Code Block was
func showRoute(routes: [MKRoute], time: NSTimeInterval) {
var directionsArray = (startingAddress: String, endingAddress: String, route: MKRoute)
for i in 0…<routes.count {
plotPolyline(routes[i])
directionsArray += [(locationArray[i].textField.text!,
locationArray[i+1].textField.text!, routes[i])]
}
displayDirections(directionsArray)
printTimeToLabel(time)
}
Swift 3 has converted this to
func showRoute(routes: [MKRoute], time: TimeInterval) {
var directionsArray = (startingAddress: String, endingAddress: String, route: MKRoute)
for i in 0…<routes.count {
plotPolyline(route: routes[i])
directionsArray += [(locationArray[i].textField?.text,
locationArray[i+1].textField?.text, routes[i])]
}
displayDirections(directionsArray: directionsArray)
printTimeToLabel(time: time)
}
This produces an error on the line
directionsArray += [(locationArray[i].textField?.text,
locationArray[i+1].textField?.text, routes[i])] Cannot convert value of type ‘[(startingAddress: String, endingAddress: String, route: MKRoute)]’ to expected argument type ‘inout _’
still crashes with a EXC_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode=0x0) in simulator even after applying all the previous changes I’m run-on iOS 10.2 and Xcode 8.2.1
Here’s what I did to fix the error Cannot convert value of type ‘[(startingAddress: String, endingAddress: String, route: MKRoute)]’ to expected argument type ‘inout _’
func showRoute(routes:[MKRoute]) {
var directionsArray = (startingAddress: String, endingAddress: String, route: MKRoute)
var directionsArrayVar = (startingAddress: String, endingAddress: String, route: MKRoute)
for i in 0…<routes.count {
plotPolyline(route: routes[i])
directionsArrayVar = [((locationArray[i].textField?.text!)!, endingAddress: (locationArray[i+1].textField?.text!)!, route: routes[i])]
directionsArray.append(contentsOf: directionsArrayVar)
}
displayDirections(directionsArray: directionsArray)
}
I know it’s not the best option but it worked for me
This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]