Plan a trip

Mobile Network SDK

  1. Prerequisites
  2. Authentication & Configuration
  3. Plan a Trip
  4. Get Quotes
  5. Book a Trip
  6. Track a Trip
  7. Testing

All trips require the location of the origin and destination and optionally the desired time for the user to be picked up.

You can use KarhooApi.addressService to help the user to pick the desired locations for their trip. This can be done in two steps.

Search for an address

First, the user enters the search query. You can use KarhooApi.addressService.placeSearch to get a list of locations that match the search query.

Please note that the Position parameter inside PlaceSearch means results will be biased to that proximity.

let addressService = Karhoo.getAddressService()
let placeSearch = PlaceSearch(
  position: Position(latitude: 42, longitude: 42),
  query: "iOS Street",
  sessionToken: "SOME_SESSION_TOKEN"
)

addressService.placeSearch(placeSearch: placeSearch).execute { result in
    switch result {
        case .success(let places):
            print("Places: \(places.places)")
        case .failure(let error):
            print("error: \(error.code) \(error.message)")
    }
}
val addressService = KarhooApi.addressService
val placeSearch = PlaceSearch(
  position = Position(latitude = 42.0, longitude = 42.0),
  query = "Android Street",
  sessionToken = "SOME_SESSION_TOKEN"
)

addressService.placeSearch(placeSearch).execute { result ->
    when (result) {
        is Resource.Success -> Log.d(result.data) // Handle data
        is Resource.Failure -> Log.d(result.error.internalMessage) //Handle errors
    }
}

Get location info

Once the user selected one of the addresses from the Places list, you can query more details about that specific Place using KarhooApi.addressService.locationInfo

let addressService = Karhoo.getAddressService()
let placeId = "SOME_PLACE_ID"
let sessionToken = "SOME_SESSION_TOKEN"
let locationInfoRequest = LocationInfoRequest(placeId: placeId, sessionToken: sessionToken)

addressService.locationInfo(locationInfoRequest: locationInfoRequest).execute { result in
    switch result {
        case .success(let locationInfo):
            print("LocationInfo: \(locationInfo)")
        case .failure(let error):
            print("error: \(error.code) \(error.message)")
    }
}
val addressService = KarhooApi.addressService
val placeId = "SOME_PLACE_ID"
val sessionToken = "SOME_SESSION_TOKEN"
val locationInfoRequest = LocationInfoRequest(placeId, sessionToken)

addressService.locationInfo(locationInfoRequest).execute { result ->
    when (result) {
        is Resource.Success -> Log.d(result.data) // Handle data
        is Resource.Failure -> Log.d(result.error.internalMessage) //Handle errors
    }
}

You need to pass the selected LocationInfos to the next step in order to retrieve the quotes


What’s Next