THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

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:{libversion}")

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:

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

To display a route on the map:

1RouteBuilder routeBuilder = new RouteBuilder(route.getCoordinates())
2 .endIcon(endIcon)
3 .startIcon(startIcon)
4 .style(routeStyle);
5final Route mapRoute = tomtomMap.addRoute(routeBuilder);
1val routeBuilder = RouteBuilder(route.getCoordinates())
2 .style(RouteStyle.DEFAULT_ROUTE_STYLE)
3 .startIcon(createIcon(R.drawable.ic_map_route_departure))
4 .endIcon(createIcon(R.drawable.ic_map_route_destination))
5 .tag(routeIdx.toString())
6tomtomMap.addRoute(routeBuilder)

API Reference

JavaDocRoutingRxJava2_2.4.807 (JavaDocRoutingRxJava2_2.4.807.zip)