Created
August 14, 2020 10:28
-
-
Save yektasarioglu/1324eacaf5ac69a57c2db892e74bb1be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getRoute(`for`: RouteType, onFailed: ((errorMessage: String) -> Unit)? = null) { | |
val originCoordinates = | |
Coordinates(userLocation?.coordinate?.first!!, userLocation?.coordinate?.second!!) | |
val destinationCoordinates = Coordinates( | |
mapKitManager?.selectedMarker?.position!!.latitude, | |
mapKitManager?.selectedMarker?.position!!.longitude | |
) | |
val routeDirection = | |
RouteDirection(origin = originCoordinates, destination = destinationCoordinates) | |
viewModelScope.launch { | |
var routeResponse: RouteResponse? = null | |
when (`for`) { | |
RouteType.WALK -> { | |
routeResponse = directionsRepository.getWalkingRoute(routeDirection) { | |
onFailed?.invoke(it) | |
} | |
} | |
RouteType.DRIVE -> { | |
routeResponse = directionsRepository.getDrivingRoute(routeDirection) { | |
onFailed?.invoke(it) | |
} | |
} | |
RouteType.BICYCLE -> { | |
routeResponse = directionsRepository.getBicyclingRoute(routeDirection) { | |
onFailed?.invoke(it) | |
} | |
} | |
} | |
stepList = routeResponse?.routes?.first()?.paths?.first()?.steps | |
routeResponse?.let { | |
mapKitManager?.removePolylines() | |
mapKitManager?.generateRoute(it) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment