The driver tracking service provides details about the driver including the drivers position, their ETA and their time of arrival to the destination in minutes. Once a trip status has been changed from confirmed to driver en-route this endpoint will be available for updates.
trackDriver trackDriver(tripId: String) : PollCall<DriverTrackingInfo>
Returns a list of locations that match a provided search query. Position inside PlaceSearch means results will be biased to that proximity. You can use the locationInfo to then get full information on a place.
sessionToken
inside PlaceSearch
indicates the session for requests. Many requests can be made with the same session token.
Parameters
tripID
: String (id of the trip)
Returns
PollCall
Errors
K4012 CouldNotGetTripCouldNotFindSpecifiedTrip
K4013 CouldNotGetTripPermissionDenied
K0004 CouldNotParseAuthorisationToken
K4013 CouldNotGetTrip
Examples
iOS
let driverTracking = Karhoo.getDriverTrackingService()
/* Polling */
// create observer
let driverTrackingObserver = Observer<DriverTrackingInfo> { [weak self] result in
switch result {
case .success(let driverTrackingInfo):
print("Driver position: \(driverTrackingInfo.position)")
case .failure(let error):
// handle error (KarhooError)
}
}
// create observable
let driverTrackingObservable = driverTracking.trackDriver(tripId: "1234").observable()
// subscribe observer to observable
driverTrackingObservable.subscribe(observer: driverTrackingObserver)
// unsubscribe observer from observable
driverTrackingObservable.unsubscribe(observer: driverTrackingObserver)
/* Single Response */
driverTracking.trackDriver(tripId: "1234").execute { [weak self] result in
switch result {
case .success(let driverTrackingInfo):
print("Driver position: \(driverTrackingInfo.position)")
case .failure(let error):
// handle error (KarhooError)
}
}
Android
// Create observer
val driverPositionObserver = object : Observer<Resource<DriverTrackingInfo>> {
override fun onValueChanged(value: Resource<DriverTrackingInfo>) {
when (value) {
is Resource.Success -> print(value.data)
is Resource.Failure -> print(value.error.internalMessage)
}
}
}
// Subscribe to observable with repeatable poll time
val tripId = "ID_OF_THE_TRIP_TO_TRACK"
val REPEAT_INTERVAL = 10000
val driverTrackingInfoObservable = driverTrackingService.trackDriver(tripId).observable().apply {
driverPositionObserver?.let {
subscribe(it, REPEAT_INTERVAL)
}
}
// Unsubscribe from observable
driverPositionObserver?.let {
driverTrackingInfoObservable?.unsubscribe(it)
}
// Single response
driverTrackingService.trackDriver(tripId).execute { result ->
when (result) {
is Resource.Success -> print(result.data) // Handle data
is Resource.Failure -> print(result.error.internalMessage) //Handle errors
}
}