Skip to content

Commit

Permalink
Added getDirectionSuggestions - to get raw response, not poyline options
Browse files Browse the repository at this point in the history
  • Loading branch information
rozkminiacz committed Mar 12, 2018
1 parent e9e1733 commit dee6834
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,33 @@ class DirectionsApiClient(

launch {
status(STATE.LOADING, STATUS.NONE)
val data = googleMapsApi.getGeocodeDirectionsResponse(getUrl(origin, dest, options)).awaitResponse()
val response = googleMapsApi.getGeocodeDirectionsResponse(getUrl(origin, dest, options)).awaitResponse()

if (data.isSuccessful) {
polylines(polylineConverter.convert(data.body()))
if (response.isSuccessful) {
polylines(polylineConverter.convert(response.body()))
status(STATE.END, STATUS.SUCCESS)
} else {
status(STATE.END, STATUS.ERROR)
}
}
}

fun getDirectionSuggestions(
origin: LatLng, dest: LatLng,
options: TransitOptions = TransitOptions(),
status: (STATE, STATUS) -> Unit = { _, _ -> },
directions: (GeocodedResponse) -> Unit
){
status(STATE.START, STATUS.NONE)

launch {
status(STATE.LOADING, STATUS.NONE)
val response = googleMapsApi.getGeocodeDirectionsResponse(getUrl(origin, dest, options)).awaitResponse()

if (response.isSuccessful) {
response.body()?.apply {
directions.invoke(this)
}
status(STATE.END, STATUS.SUCCESS)
} else {
status(STATE.END, STATUS.ERROR)
Expand Down

0 comments on commit dee6834

Please sign in to comment.