Android Native - Itinerary service
The know the implemented features and the coverage please refers to the Routing API page
Itinerary Service
The itineraries used in the WemapMapSDK
are generated by the Wemap Routing API. When you install the WemapMapSDK
, it also includes WemapCoreSDK
which has IItineraryService
interface, which provides a convenient way to access the Wemap Routing API.
To generate an itinerary, you'll need to obtain an implementation of IItineraryService
and request for itinerary computation using ItineraryParameters
class. You also can use the ItinerarySearchOptions
class to set a few options.
Wemap Routing API provides different travel modes for itinerary computation: Walk
, Car
and Bike
. Bike
travel mode also can have TravelMode.Preference
: DEFAULT
, SAFEST
, FASTEST
and TOURISM
.
Below are examples of how you can use specific options to compute itineraries for a few scenarios.
The code examples below show how to use the WemapCoreSDK
without the WemapMapSDK
, but if you use WemapMapSDK
- this logic is managed by ItineraryManager
and MapNavigationManager
of WemapMapSDK
.
Compute itinerary
This example demonstrates how to calculate walking itineraries with origin and destination coordinates.
import android.os.Bundle
import androidx.activity.ComponentActivity
import com.getwemap.sdk.core.internal.CoreConstants
import com.getwemap.sdk.core.model.ServiceFactory
import com.getwemap.sdk.core.model.entities.Coordinate
import com.getwemap.sdk.core.model.services.IItineraryService
import com.getwemap.sdk.core.model.services.parameters.ItineraryParameters
import io.reactivex.rxjava3.disposables.CompositeDisposable
class MainActivity : ComponentActivity() {
private val disposeBag = CompositeDisposable()
private val service = ServiceFactory.getItineraryService()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
computeItineraries()
}
private fun computeItineraries() {
val origin = Coordinate(43.610628, 3.876654)
val destination = Coordinate(43.609011, 3.917091)
val parameters = ItineraryParameters(origin, destination) // default travelMode is Walk()
val disposable = service
.itineraries(parameters)
.subscribe({
println("response - $it")
}, {
println("error - $it")
})
disposeBag.add(disposable)
}
}
You can specify travel mode and preference for the request:
private fun computeItineraries() {
...
val parameters = ItineraryParameters(origin, destination, TravelMode.Bike(TravelMode.Preference.SAFEST))
...
}
Also is some cases you may need to specify search options:
private fun computeItineraries() {
...
val parameters = ItineraryParameters(origin, destination, TravelMode.Walk(), ItinerarySearchOptions(avoidStairs = true))
...
}
Examples
For additional examples and sample implementations of WemapSDKs, visit the official GitHub repository.
Clone the repository and follow the README instructions to run the sample application.