HERE Android SDK Developer's Guide

Transit Routing

Transit Routes are routes calculated by using CoreRouter with the the RouteOptions transport mode set to PUBLIC_TRANSPORT. With the transit routing feature, you can calculate transit routes by using known online timetable information.

Note:
  • RouteOptions.TransportMode.PUBLIC_TRANSPORT is supported since HERE SDK v3.4.
  • To use this feature, your application must include the Gson library (release 2.2.4 or a compatible version) on its class path.

Before displaying transit routing, you should set the map scheme to include transit so that the MapRoute shows the color of the transit lines.

// sets the map scheme to include transit.
map.setMapScheme(Map.Scheme.NORMAL_DAY_TRANSIT);

The following is an example of a transit route using CoreRouter:

  ...
  CoreRouter router = new CoreRouter();

  // Select routing options
  RoutePlan routePlan = new RoutePlan();

  RouteOptions routeOptions = new RouteOptions();
  routeOptions.setTransportMode(RouteOptions.TransportMode.PUBLIC_TRANSPORT);
  routeOptions.setRouteType(RouteOptions.Type.FASTEST);
  routePlan.setRouteOptions(routeOptions);

  // Select Waypoints for your routes
  routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(49.1966286, -123.0053635)));
  routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(49.1947289, -123.1762924)));
  router.calculateRoute(routePlan, new RouterListener());

...

private final class RouterListener implements CoreRouter.Listener {

  // Method defined in Listener
  public void onProgress(int percentage) {
    // Display a message indicating calculation progress
  }

  // Method defined in Listener
  public void onCalculateRouteFinished(List<RouteResult> routeResult, RoutingError error) {
    // If the route was calculated successfully
    if (error == RoutingError.NONE) {
      // Render the route on the map
      mapRoute = new MapRoute(routeResult.get(0).getRoute());
      map.addMapObject(mapRoute);

      // Get the bounding box containing the route and zoom in (no animation)
      GeoBoundingBox gbb = routeResult.get(0).getRoute().getBoundingBox();
      map.zoomTo(gbb, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
    }
    else {
      // Display a message indicating route calculation failure
    }
  }
}
Figure 1. Transit Route

The TransitRouteElement Class

Transit route elements, which are route element objects specific to public transit, can be retrieved from the getTransitElement() method in the RouteElement class.

Online Timetables

By default, transit routes and times are calculated according to static estimations of each leg of the trip. However, it is possible for the HERE SDK to query the online timetable data that is available from municipalities. This type of transit routing can be performed automatically without additional coding effort, but the following conditions must be fulfilled:

  • Your application must have an active data connection, and CoreRouter must be set to Connectivity.DEFAULT or Connectivity.ONLINE.
  • The route must be between two endpoints—an origin and a destination. Multiple endpoints are not supported.
  • You are required to display the source attribution, retrieved through the Route.getTransitRouteSourceAttribution() method, somewhere near the route results.

This type of calculation only returns a maximum of ten route results, even if the limit set in the RouteOptions.setRouteCount(int) exceeds it.

Note: The following route options are ignored in this route calculation mode:
  • setTransitMinimumChangeTime(int)
  • setTransitWalkTimeMultiplier(int)
In addition, the setTransitMaximumChanges(int) option is supported in the primary route result, but the maximum number of changes is capped at 10.
Note: Contractual limitations exist for Online Timetable coverage in Paris, France and Germany. See Service Support to contact us for more details.