Itineraries
The itineraries used in the WemapSDKs are generated by the Wemap Routing API. The way you interact with the Wemap Routing API varies depending on which WemapSDK you use.
When you use:
WemapMapSDKuse:MapNavigationManagerinterface to compute itineraries and start navigation immediately.ItineraryManagerclass to compute and preview itineraries before starting a navigation.
WemapGeoARSDKuse:ARNavigationManagerinterface to compute itineraries and start navigation immediately.
WemapCoreSDKuse:ItineraryProvider(obtained viasession.itineraryProvider) to compute itineraries.
To generate an itinerary, you'll need to provide a destination, optionally origin and other options depending on which WemapSDK you use. You also can use the ItinerarySearchRules class to set a few search rules.
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.
Map Navigation Manager (WemapMapSDK)
To generate an itinerary and start navigation, you'll need to obtain an instance implementing MapNavigationManager from MapView.
fun startNavigation() {
val origin = Coordinate(43.610628, 3.876654)
val destination = Coordinate(43.609011, 3.917091)
val navigationOptions = NavigationOptions(stopWhenArrivedAtDestination = false) // NavigationOptions available for Map and AR SDKs
val itineraryOptions = ItineraryOptions(indoorLine = LineOptions(color = Color.RED)) // ItineraryOptions available only for WemapMapSDK
val searchRules = ItinerarySearchRules.WHEELCHAIR // ItinerarySearchRules available for all SDKs
lifecycleScope.launch {
runCatching {
mapView.navigationManager
.startNavigation(
origin, destination,
TravelMode.Walk(), // can be omitted because it's default mode
navigationOptions, searchRules, itineraryOptions,
10.seconds // default value is 30 seconds
)
}.onSuccess {
println("Successfully started navigation from: $origin to: $destination")
// The SDK sets the camera mode after navigation starts (defaults to TRACKING_COMPASS).
}.onFailure {
println("Failed to start navigation from $origin to: $destination with error: $it")
}
}
}
Itinerary manager (WemapMapSDK)
To generate an itinerary for preview, you'll need to obtain an instance of ItineraryManager class from MapView.
fun getItinerariesForPreview() {
val origin = Coordinate(43.610628, 3.876654)
val destination = Coordinate(43.609011, 3.917091)
val searchRules = ItinerarySearchRules.WHEELCHAIR // ItinerarySearchRules available for all SDKs
lifecycleScope.launch {
runCatching {
mapView.itineraryManager
.computeItineraries(
origin, destination,
TravelMode.Walk(), // can be omitted because it's default mode
searchRules
)
}.onSuccess {
println("Successfully started navigation from: $origin to: $destination")
mapView.locationManager.cameraMode = CameraMode.TRACKING_COMPASS // track user movements
mapView.itineraryManager.addItinerary(it.first()) // draw preview
}.onFailure {
println("Failed to start navigation from $origin to: $destination with error: $it")
}
}
}
AR Navigation Manager (WemapGeoARSDK)
To generate an itinerary and start navigation, you'll need to obtain an instance implementing ARNavigationManager from GeoARView.
fun startNavigation() {
val origin = Coordinate(43.610628, 3.876654)
val destination = Coordinate(43.609011, 3.917091)
val navigationOptions = NavigationOptions(stopWhenArrivedAtDestination = false) // NavigationOptions available for Map and AR SDKs
val searchRules = ItinerarySearchRules.WHEELCHAIR // ItinerarySearchRules available for all SDKs
lifecycleScope.launch {
runCatching {
geoARView.navigationManager
.startNavigation(
origin, destination,
TravelMode.Walk(), // can be omitted because it's default mode
navigationOptions, searchRules,
10.seconds // default value is 30 seconds
)
}.onSuccess {
println("Successfully started navigation from: $origin to: $destination")
}.onFailure {
println("Failed to start navigation from $origin to: $destination with error: $it")
}
}
}
Itinerary Provider (WemapCoreSDK)
To generate an itinerary, obtain the ItineraryProvider from your session (session.itineraryProvider)
and call itineraries(...). It returns a List<Itinerary>.
Below are examples of how you can use specific options to compute itineraries for a few scenarios.
Compute itinerary
This example demonstrates how to calculate walking itineraries with origin and destination coordinates.
fun computeItineraries() {
val origin = Coordinate(43.610628, 3.876654)
val destination = Coordinate(43.609011, 3.917091)
lifecycleScope.launch {
runCatching {
session.itineraryProvider.itineraries(origin, destination) // default travelMode is Walk()
}.onSuccess {
println("itineraries - $it")
setupItinerary(it.first())
}
.onFailure {
println("error - $it")
}
}
}
You can specify travel mode and preference for the request:
session.itineraryProvider.itineraries(
origin, destination, TravelMode.Bike(TravelMode.Preference.FASTEST)
)
Also is some cases you may need to specify search rules:
session.itineraryProvider.itineraries(
origin, destination, TravelMode.Walk(), ItinerarySearchRules.WHEELCHAIR
)
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.