THIS SDK ISDEPRECATED. We rolled out a new and better SDK for you.
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:
Copy implementation ( "com.tomtom.online:sdk-routing-rxjava2:{libversion}" )
To initialize the Rx wrapper of the RoutingApi
:
Copy RxRoutingApi routingApi = new RxRoutingApi ( context , BuildConfig . ROUTING_API_KEY )
Copy private val rxRoutingApi = RxRoutingApi ( context , BuildConfig . ROUTING_API_KEY )
You can subscribe to the Routing API results by calling the following code:
Copy 1 Disposable disposable = routingApi . planRoute ( routeSpecification )
2 . subscribeOn ( getWorkingScheduler ( ) )
3 . observeOn ( getResultScheduler ( ) )
5 routePlan -> displayFullRoutes ( routePlan ) ,
6 throwable -> proceedWithError ( throwable . getMessage ( ) )
Copy 1 val disposable = rxRoutingApi . planRoute ( routeSpecification )
2 . subscribeOn ( workingScheduler )
3 . observeOn ( resultScheduler )
5 { routePlan -> result . value = Resource . success ( routePlan ) } ,
6 { result . value = Resource . error ( Error ( it ) ) }
To display a route on the map:
Copy 1 RouteBuilder routeBuilder = new RouteBuilder ( route . getCoordinates ( ) )
5 final Route mapRoute = tomtomMap . addRoute ( routeBuilder ) ;
Copy 1 val 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 ( ) )
6 tomtomMap . addRoute ( routeBuilder )
API Reference
JavaDocRoutingRxJava2_2.4.807 (JavaDocRoutingRxJava2_2.4.807.zip )