Search code examples
androidhere-api

Does here api allow enabling traffic in calculateRoute function


Can I enable traffic information when specifying the route options in calculateRoute function? I'm using here sdk in my application

This is my caclulateRoute function

final RouteOptions routeOptions = new RouteOptions();                   
routeOptions.setTruckLength(25);                                        
routeOptions.setTruckHeight(5);                                         
routeOptions.setTruckWidth(2.5f);                                       
routeOptions.setTruckLimitedWeight(40);                                 
routeOptions.setTruckWeightPerAxle(10);                                 
routeOptions.setTruckTrailersCount(1);                                  

RoutePlan routePlan = new RoutePlan();                                  
routePlan.setRouteOptions(routeOptions);                                

for (GeoCoordinate coordinate : locations) {                            
    RouteWaypoint routeWaypoint = new RouteWaypoint(coordinate);        
    routePlan.addWaypoint(routeWaypoint);                               
}                                                                       

CoreRouter coreRouter = new CoreRouter();                               
coreRouter.setConnectivity(CoreRouter.Connectivity.DEFAULT);            
coreRouter.calculateRoute(routePlan,.......

I was asking is there any way to specify that we should consider traffic information also while calculating route.


Solution

  • Assuming you are talking about the Premium SDK (since you refer already to Core router anyway):

    The CoreRouter has a method:

    setDynamicPenalty(DynamicPenalty penalty)

    https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/routing/DynamicPenalty.html

    One of the "penalty" modes is TrafficPenalty:

    setTrafficPenaltyMode(Route.TrafficPenaltyMode mode)

    https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/routing/DynamicPenalty.html#setTrafficPenaltyMode-com.here.android.mpa.routing.Route.TrafficPenaltyMode-

    Setting the traffic penalty mode to OPTIMAL is probably what you are looking for.