Sorry, you need to enable JavaScript to visit this website.

Routing Extensions

Routing Extensions

Routing Reactive Extensions

This library consists of additional classes that allow you to write reactive components using the Routing API. The Routing API contains methods that transform the results into Single which can easily be integrated with RxJava2. This module does not add any new features to the existing Routing API module.

To use reactive extensions, add the following dependency to the build.gradle file:

implementation("com.tomtom.online:sdk-routing-rxjava2:2.4602")

To initialize the Rx wrapper of the RoutingApi:

_

RxRoutingApi routingApi = new RxRoutingApi(context, BuildConfig.ROUTING_API_KEY);
private val rxRoutingApi = RxRoutingApi(context, BuildConfig.ROUTING_API_KEY)

 

You can subscribe to the Routing API results by calling the following code:

_

Disposable disposable = routingApi.planRoute(routeSpecification)
        .subscribeOn(getWorkingScheduler())
        .observeOn(getResultScheduler())
        .subscribe(
                routePlan -> displayFullRoutes(routePlan),
                throwable -> proceedWithError(throwable.getMessage())
        );
val disposable = rxRoutingApi.planRoute(routeSpecification)
    .subscribeOn(workingScheduler)
    .observeOn(resultScheduler)
    .subscribe(
        { routePlan -> result.value = Resource.success(routePlan) },
        { result.value = Resource.error(Error(it)) }
    )

 

To display a route on the map:

_

RouteBuilder routeBuilder = new RouteBuilder(route.getCoordinates())
        .endIcon(endIcon)
        .startIcon(startIcon)
        .style(routeStyle);
final Route mapRoute = tomtomMap.addRoute(routeBuilder);
val routeBuilder = RouteBuilder(route.getCoordinates())
    .style(RouteStyle.DEFAULT_ROUTE_STYLE)
    .startIcon(createIcon(R.drawable.ic_map_route_origin))
    .endIcon(createIcon(R.drawable.ic_map_route_destination))
    .tag(routeIdx.toString())
tomtomMap.addRoute(routeBuilder)