Skip to main content
GuidesAPI ReferenceExamplesFAQ

Handling RoutePreferences

|

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. Used with PT Routes to specify the desired arrival/departure time. It represents the local time of the route start/end, but with the isUtc flag set to truenull (current time will be used)
transportModeTransport mode for the route.RouteTransportMode.car
warning

In order to compute the timestamp in the required format, please check the snippet below:

final departureLandmark = Landmark.withLatLng(latitude: 45.65, longitude: 25.60);
final destinationLandmark = Landmark.withLatLng(latitude: 46.76, longitude: 23.58);

TimezoneService.getTimezoneInfoFromCoordinates(
coords: departureLandmark.coordinates,
time: DateTime.now().add(Duration(hours: 1)), // Compute time for one hour later
onComplete: (error, result) {
if (error != GemError.success) {
// Handle error
return;
} else {
final timestamp = result!.localTime;
// Pass the timestamp to RoutePreferences
}
},
);

Check the Timezone Service guide for more details.

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 and lorry transport mode.
final routePreferences = RoutePreferences(
truckProfile: truckProfile,
transportMode: RouteTransportMode.lorry, // <- This field is crucial
);

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.

Computing caravan routes

Certain vehicles, such as caravans or trailers, may be restricted on some roads due to their size or weight, yet still permitted on roads where trucks are prohibited.

To calculate routes for caravans or trailers, we can use the truckProfile field of RoutePreferences with the appropriate dimensions and weight.

// 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
);

// Define the route preferences with current truck profile and car transport mode.
final routePreferences = RoutePreferences(
truckProfile: truckProfile,
transportMode: RouteTransportMode.car, // <- This field is crucial to distinguish caravan from truck
);

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

At least one of the fields height, length, width or axleLoad must be set to a non-zero value in order for the settings to be taken into account during routing. If all these fields are set to 0 then a normal car route will be calculated.