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 create an instance 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 NavigationManager
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 by lazy {
ServiceFactory
.createService(IItineraryService::class.java, CoreConstants.ITINERARIES_BASE_URL)
}
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))
...
}
Navigation information
The NavigationInfo
class contains all information about the user's progress along the itinerary, including the current leg and step information. This object allows you to get distance and time measurements, previous and next steps, and more.
The NavigationInfoHandler
helps to get updated information about the user’s progress along the itinerary on request by providing an updated NavigationInfo
object.
import android.os.Bundle
import android.os.Handler
import android.os.Looper
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.entities.Itinerary
import com.getwemap.sdk.core.model.entities.TravelMode
import com.getwemap.sdk.core.model.services.IItineraryService
import com.getwemap.sdk.core.model.services.parameters.ItineraryParameters
import com.getwemap.sdk.core.navigation.NavigationInfoHandler
import io.reactivex.rxjava3.disposables.CompositeDisposable
class MainActivity : ComponentActivity() {
private val disposeBag = CompositeDisposable()
private val service by lazy {
ServiceFactory
.createService(IItineraryService::class.java, CoreConstants.ITINERARIES_BASE_URL)
}
private val infoHandler = NavigationInfoHandler()
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, TravelMode.Bike(TravelMode.Preference.FASTEST))
val disposable = service
.itineraries(parameters)
.subscribe({
println("response - $it")
setupItinerary(it.itineraries.first())
}, {
println("error - $it")
})
disposeBag.add(disposable)
}
private fun setupItinerary(itinerary: Itinerary) {
infoHandler.itinerary = itinerary
// request for an update of the navigation information with a certain time interval
Handler(Looper.getMainLooper()).postDelayed({
getNavigationInfo(Coordinate(43.610107, 3.891805))
}, 5000)
}
private fun getNavigationInfo(userPosition: Coordinate) {
val info = infoHandler.getNavigationInfo(userPosition)
println("navigation info - $info")
}
}
Examples
You can find additional examples for the WemapSDKs on GitHub. Clone the repository and run the example application following the instructions in the README.