Planning a route

VERSION 0.3.1056
PUBLIC PREVIEW

Requesting routes

To calculate a route from A to B, you need to provide route planning criteria. They are built using the RoutePlanningOptions class. You can take advantage of the named parameters in Kotlin to choose the properties that you need. The only required parameters is itinerary. There are multiple optional parameters that you can use to shape the route planning criteria to fit your use cases. For a detailed description of available parameters, see the Routing API documentation.

1val amsterdam = GeoPoint(52.377956, 4.897070)
2val rotterdam = GeoPoint(51.926517, 4.462456)
3val routePlanningOptions = RoutePlanningOptions(
4 itinerary = Itinerary(origin = amsterdam, destination = rotterdam),
5 costModel = CostModel(routeType = RouteType.Efficient),
6 vehicle = Vehicle.Truck(),
7 alternativeRoutesOptions = AlternativeRoutesOptions(maxAlternatives = 2)
8)

Once you have a RoutePlanningOptions object, provide it to the planRoute method. This can be done asynchronously using the RoutePlanningCallback, or synchronously as described in the Synchronous routing call. If the route planning is successful, the onSuccess(RoutePlanningResult) method is called. If an error occurred, it is in RoutingError.

1routePlanner.planRoute(
2 routePlanningOptions,
3 object : RoutePlanningCallback {
4 override fun onSuccess(result: RoutePlanningResult) {
5 /* YOUR CODE GOES HERE */
6 }
7
8 override fun onError(error: RoutingError) {
9 /* YOUR CODE GOES HERE */
10 }
11
12 override fun onRoutePlanned(route: Route) {
13 /* YOUR CODE GOES HERE */
14 }
15 }
16)

Route with alternatives

Adjusting route planning criteria

Route types

The route type parameter specifies the type of optimization used when calculating routes:

  • Fast: Route calculation is optimized by travel time, while keeping the routes sensible. For example, the calculation may avoid shortcuts along inconvenient side roads or long detours that only save very little time.
  • Short: Route calculation is optimized by travel distance, while keeping the routes sensible. For example, straight routes are preferred over those incurring turns.
  • Efficient: Route calculation is optimized so that a good compromise between small travel time and low fuel or energy consumption is achieved.
  • Thrilling: Route calculation is optimized so that routes include interesting or challenging roads and use as few motorways as possible.
    • You can choose the level of turns included and also the degree of hilliness. See the hilliness and windingness parameters to set this.
    • There is a limit of 900km on routes planned with thrilling route type.

Default value is set to Fast.

Avoids

The RoutePlanningOptions.costModel.avoidOptions.avoidTypes parameter specifies something that the route calculation should try to avoid when determining the route. The avoid can be specified multiple times. Possible values are:

Vehicle

The Vehicle contains parameters relevant for selecting suitable routes. It also provides information about the current state, e.g., the level of fuel. Some roads in the map have vehicle and time dependent restrictions. For example, roads may restrict traffic to pedestrians, or can only be used by electric vehicles. Roads may prohibit vehicles carrying hazardous materials. Tunnels may only be passable by vehicles up to a maximum height, and for trucks with the proper tunnel code.

Vehicles are distinguished by type. Each vehicle type has a different constructor which takes exactly those parameters that are useful for that type. For example, dimensions are only meaningful for motorized vehicles, and not for bikes and pedestrians.

Vehicles have the following properties:

  • A type, e.g. car, motorcycle, truck.
  • A maximum speed.
  • Motorized vehicles can have an engine, either combustion or electric or both for a hybrid vehicle.
    • Pedestrians and bicycles do not support engines.
    • Each engine can contain consumption parameters used to predict the vehicle range.
    • Motorized vehicles may have dimensions.
    • They can be commercial transports.
  • Trucks may have a load for which restrictions apply:
    • A hazmat classification of the load can restrict usable roads.
    • An ADR tunnel code describes which tunnels can be used.

Some vehicle properties are valid only at the current point in time and get updated over time, e.g. the fuel amount/charge level. Vehicle data is also useful during free driving mode without a route, e.g. for range features like 360 range around your current position.

Planning errors

A RoutingError is returned if any error occurred during the Routing API call. There are a few `RoutingError`s that are returned in different situations.

Next steps

Since you have learned how to plan a route, here are recommendations for the next steps: