Skip to main content
GuidesAPI ReferenceExamplesFAQ

Handling Route Preferences

|

This guide explains how to customize routes using preferences, configure vehicle profiles, and apply routing constraints for different transport modes.


Configure route preferences

Set route options using RoutePreferences to customize route calculations.

Generic route options:

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
Tip

Compute the timestamp in the required format using this approach:

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
}
},
);

See the Timezone Service guide for detailed information.

Complex structure creation options:

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

Vehicle profile options:

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

Route avoidance options:

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 vehicle options:

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

Public transport options:

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.[]

Example calculating the fastest car route with terrain profile:

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

Read-only properties that indicate how the route was computed:

PreferenceExplanationDefault Value
routeResultTypeType of route result.RouteResultType.path

Configure vehicle profiles

Customize routing behavior for different vehicle types using profile configurations.

Car profile

Define car-specific routing preferences using the CarProfile class.

Available options:

MemberTypeDefaultDescription
fuelFuelTypepetrolEngine fuel type
massint0 - not considered in routing.Vehicle mass in kg.
maxSpeeddouble0 - not considered in routing.Vehicle max speed in m/s. Not considered in routing.
plateNumberstring""Vehicle plate number.

FuelType values: petrol, diesel, lpg (liquid petroleum gas), electric.

All fields except fuel default to 0, meaning they are not considered in routing. The fuel field defaults to FuelType.diesel.

Truck profile

Define truck-specific routing preferences using the TruckProfile class.

Available options:

MemberTypeDefaultDescription
axleLoadint0 - not considered in routingTruck axle load in kg.
fuelFuelTypepetrolEngine fuel type.
heightint0 - not considered in routingTruck height in cm.
lengthint0 - not considered in routingTruck length in cm.
massint0 - not considered in routingVehicle mass in kg.
maxSpeeddouble0 - not considered in routingVehicle max speed in m/s.
widthint0 - not considered in routingTruck width in cm.
plateNumberstring""Vehicle plate number.

Electric bike profile

Define electric bike-specific routing preferences using the ElectricBikeProfile class.

Available options:

MemberTypeDefaultDescription
auxConsumptionDaydouble0 - default value is usedBike auxiliary power consumption during day in Watts.
auxConsumptionNightdouble0 - default value is usedBike auxiliary power consumption during night in Watts.
bikeMassdouble0 - default value is usedBike mass in kg.
bikerMassdouble0 - default value is usedBiker mass in kg.
ignoreLegalRestrictionsboolfalseIgnore country-based legal restrictions related to e-bikes.
typeElectricBikeTypeElectricBikeType.noneE-bike type.
plateNumberstring""Vehicle plate number.

The ElectricBikeProfile class is encapsulated within the BikeProfileElectricBikeProfile class, together with the BikeProfile enum.


Calculate truck routes

Compute routes optimized for trucks by configuring truck-specific preferences and constraints.

Set the truckProfile field in 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
});

Calculate caravan routes

Compute routes for caravans and trailers with size and weight restrictions.

Caravans or trailers may be restricted on some roads due to size or weight, yet still permitted on roads where trucks are prohibited.

Use the truckProfile field in RoutePreferences with 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
});

Set at least one of height, length, width, or axleLoad to a non-zero value for the settings to take effect. If all fields are 0, a normal car route is calculated.


Calculate round trips

Generate routes that start and end at the same location using roundtrip parameters.

Key differences from normal routing:

  • Waypoint requirements - Normal routes require at least two waypoints. Roundtrips need only one departure point; additional waypoints are ignored. The algorithm generates multiple output waypoints automatically
  • Determinism - Normal routing produces the same route when inputs remain unchanged. Roundtrip generation is random by design, creating different routes each time. Use a seed value for deterministic results
  • Preferences - All normal routing preferences apply, including vehicle profiles and fitness factors

Range types

The RangeType enumeration specifies units for the range parameter:

RangeType valueDescription
defaultTypeUses distanceBased for shortest routes; timeBased for all other route types
distanceBasedDistance measured in meters
timeBasedDuration measured in seconds
(energyBased)Not currently supported
Tip

Specify distanceBased or timeBased explicitly to avoid confusion. A value of 10,000 means 10 km for distance-based requests but ~3 hours for time-based requests.

Roundtrip parameters

Configure roundtrips using RoundTripParameters:

ParameterTypeDescription
rangeintTarget length or duration. The algorithm approximates this value but does not guarantee exact matches
rangeTypeRangeTypeUnits for the range value (distance or time)
randomSeedintSet to 0 for random generation each time. Any other value produces deterministic results when other parameters remain unchanged

Create a round trip route

Set roundTripParameters in RoutePreferences with a non-zero range value:

// Define round trip preferences
final tripPreferences = RoundTripParameters(range: 5000, rangeType: RangeType.distanceBased);
// Define route preferences to include round trip parameters
final routePreferences = RoutePreferences(
transportMode: RouteTransportMode.bicycle,
roundTripParameters: tripPreferences,
);

// Use only the departure landmark to calculate a round trip route
final routingHandler = RoutingService.calculateRoute([departureLandmark], routePreferences,
(err, routes) {
// Handle routing results
});
Round trip presented
danger

If more than one waypoint is provided in a round trip calculation, only the first is considered; others are ignored.