Skip to main content
GuidesAPI ReferenceExamplesFAQ

Handling RoutePreferences

Estimated reading time: 5 minutes

Before computing a route, we need to specify some route options.

The most generic supported route options are briefly presented in the following table.

PreferenceExplanationDefault Value
accurateTrackMatchEnables accurate track matching for routes.true
allowOnlineCalculationAllows online calculations.true
alternativeRoutesBalancedSortingBalances sorting of alternative routes.true
alternativesSchemaDefines the schema for alternative routes.RouteAlternativesSchema.defaultSchema
automaticTimestampAutomatically includes a timestamp.true
departureHeadingSets departure heading and accuracy.DepartureHeading(heading: -1, accuracy: 0)
ignoreRestrictionsOverTrackIgnores restrictions over the track.false
maximumDistanceConstraintEnables maximum distance constraints.true
pathAlgorithmAlgorithm used for path calculation.RoutePathAlgorithm.ml
pathAlgorithmFlavorFlavor for the path algorithm.RoutePathAlgorithmFlavor.magicLane
resultDetailsLevel of details in the route result.RouteResultDetails.full
routeRangesRanges for the routes.[]
routeRangesQualityQuality level for route ranges.100
routeTypePreferred route type.RouteType.fastest
timestampCustom timestamp for the route.null
transportModeTransport mode for the route.RouteTransportMode.car

Enabling complex structures creation options are presented in the following table:

PreferenceExplanationDefault Value
buildConnectionsEnables building of route connections.false
buildTerrainProfileEnables building of terrain profile.BuildTerrainProfile(enable: false)

Route specific options for custom profiles are presented in the following table:

PreferenceExplanationDefault Value
bikeProfileProfile configuration for bikes.null
carProfileProfile configuration for cars.null
evProfileProfile configuration for electric vehicles.null
pedestrianProfileProfile configuration for pedestrians.PedestrianProfile.walk
truckProfileProfile configuration for trucks.null

Avoid options are presented in the following table:

PreferenceExplanationDefault Value
avoidBikingHillFactorFactor to avoid biking hills.0.5
avoidCarpoolLanesAvoids carpool lanes.false
avoidFerriesAvoids ferries in the route.false
avoidMotorwaysAvoids motorways in the route.false
avoidTollRoadsAvoids toll roads in the route.false
avoidTrafficStrategy for avoiding traffic.TrafficAvoidance.none
avoidTurnAroundInstructionAvoids turn-around instructions.false
avoidUnpavedRoadsAvoids unpaved roads in the route.false

Emergency vehicles preferences are shown in the following table:

PreferenceExplanationDefault Value
emergencyVehicleExtraFreedomLevelsExtra freedom levels for emergency vehicles.0
emergencyVehicleModeEnables emergency vehicle mode.false

Public Transport preferences are shown in the following table:

PreferenceExplanationDefault Value
algorithmTypeAlgorithm type used for routing.PTAlgorithmType.departure
minimumTransferTimeInMinutesMinimum transfer time in minutes.1
maximumTransferTimeInMinutesSets maximum transfer time in minutes.300
maximumWalkDistanceMaximum walking distance in meters.5000
sortingStrategyStrategy for sorting routes.PTSortingStrategy.bestTime
routeTypePreferencesPreferences for route types.RouteTypePreferences.none
useBikesEnables use of bikes in the route.false
useWheelchairEnables wheelchair-friendly routes.false
routeGroupIdsEarlierLaterIDs for earlier/later route groups.[]

A short example of how they can be used to compute the fastest car route and also to compute a terrain profile is presented below:

final routePreferences = RoutePreferences(
transportMode: RouteTransportMode.car,
routeType: RouteType.fastest,
buildTerrainProfile: BuildTerrainProfile(enable: true));

There are also properties that can't be set and only can be obtained for a route, in order to know how that route was computed:

PreferenceExplanationDefault Value
routeResultTypeType of route result.RouteResultType.path

Computing truck routes

To compute routes for trucks we can write code like the following by initializing the truckProfile field of RoutePreferences:

// Define the departure.
final departureLandmark =
Landmark.withLatLng(latitude: 48.87126, longitude: 2.33787);

// Define the destination.
final destinationLandmark =
Landmark.withLatLng(latitude: 51.4739, longitude: -0.0302);

final truckProfile = TruckProfile(
height: 180, // cm
length: 500, // cm
width: 200, // cm
axleLoad: 1500, // kg
maxSpeed: 60, // km/h
mass: 3000, // kg
fuel: FuelType.diesel
);

// Define the route preferences with current truck profile.
final routePreferences = RoutePreferences(truckProfile: truckProfile);

TaskHandler? taskHandler = RoutingService.calculateRoute(
[departureLandmark, destinationLandmark], routePreferences,
(err, routes) {
// handle results
});

FuelType can have the following values: petrol, diesel, lpg (liquid petroleum gas), electric.

By default, all field except fuel have default value 0, meaning they are not considered in the routing. fuel by default is FuelType.diesel.