Skip to main content
GuidesAPI ReferenceExamplesFAQ

Get started with routing

|

This guide explains how to calculate routes, customize routing preferences, retrieve turn-by-turn instructions, and access detailed route information including terrain profiles and traffic events.

Here’s a quick overview of what you can do with routing:

  • Calculate routes from a start point to a destination.
  • Include intermediary waypoints for multi-stop routes.
  • Compute range routes to determine areas reachable within a specific range.
  • Plan routes over predefined tracks.
  • Customize routes with preferences like route types, restrictions, and more.
  • Retrieve maneuvers and turn-by-turn instructions.
  • Access detailed route profiles for further analysis.

Calculate routes

Calculate a navigable route between a start point and destination. The route can be used for navigation or simulation.

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

// Define the destination.
final destinationLandmark =
Landmark.withLatLng(latitude: 50.84644, longitude: 4.34587);

// Define the route preferences (all default).
final routePreferences = RoutePreferences();

TaskHandler? taskHandler = RoutingService.calculateRoute(
[departureLandmark, destinationLandmark], routePreferences,
(err, routes) {
if (err == GemError.success) {
showSnackbar("Number of routes: ${routes.length}");
} else if (err == GemError.cancel) {
showSnackbar("Route computation canceled");
} else {
showSnackbar("Error: $err");
}
});
info

The RoutingService.calculateRoute method returns null only when the computation fails to initiate. In such cases, calling RouteService.cancelRoute(taskHandler) is not possible. Error details are delivered through the onComplete function.

The callback function's err parameter can return these values:

ValueSignificance
GemError.successsuccessfully completed
GemError.cancelcancelled by the user
GemError.waypointAccesscouldn't be found with the current preferences
GemError.connectionRequiredif allowOnlineCalculation = false in the routing preferences and the calculation can't be done on the client side due to missing data
GemError.expiredcalculation can't be done on client side due to missing necessary data and the client world map data version is no longer supported by the online routing service
GemError.routeTooLongrouting was executed on the online service and the operation took too much time to complete (usually more than 1 min, depending on the server overload state)
GemError.invalidatedthe offline map data changed ( offline map downloaded, erased, updated ) during the calculation
GemError.noMemoryrouting engine couldn't allocate the necessary memory for the calculation

Cancel an ongoing route computation if needed:

RoutingService.cancelRoute(taskHandler);

When the route is canceled, the callback returns err = GemError.cancel.


Retrieve time and distance information

Access estimated time of arrival (ETA), distance, and traffic details for computed routes.

Get time and distance information using the Route.getTimeDistance method:

TimeDistance td = route.getTimeDistance(activePart: false);

final totalDistance = td.totalDistanceM;
// same with:
//final totalDistance = td.unrestrictedDistanceM + td.restrictedDistanceM;

final totalDuration = td.totalTimeS;
// same with:
//final totalDuration = td.unrestrictedTimeS + td.restrictedTimeS;

// by default activePart = true
TimeDistance remainTd = route.getTimeDistance(activePart: true);

final totalRemainDistance = remainTd.totalDistanceM;
final totalRemainDuration = remainTd.totalTimeS;

Set activePart to false to compute time and distance for the entire route, or true (default) for only the remaining portion.

Unrestricted refers to public property routes, while restricted refers to private property routes. Time is measured in seconds and distance in meters.

Access traffic events

Retrieve traffic event details for the route:

List<RouteTrafficEvent> trafficEvents = route.trafficEvents;

for (final event in trafficEvents) {
RouteTransportMode transportMode = event.affectedTransportModes;
String description = event.description;
TrafficEventClass eventClass = event.eventClass;
TrafficEventSeverity eventSeverity = event.eventSeverity;
Coordinates from = event.from;
Coordinates to = event.to;
bool isRoadBlock = event.isRoadblock;
}

See the Traffic Events guide for detailed information.


Display routes on the map

Routes are not automatically displayed after calculation. Visualize routes on the map using the display methods.

Refer to the display routes on maps guide for visualization and customization options.

Get the Terrain Profile

When computing the route we can choose to also build the TerrainProfile for the route.

In order to do that RoutePreferences must specify we want to also generate the BuildTerrainProfile:

final routePreferences = RoutePreferences(
buildTerrainProfile: const BuildTerrainProfile(enable: true),
);
danger

Set BuildTerrainProfile with enable flag to true in the preferences for calculateRoute to retrieve terrain profile data.

Access elevation and terrain data from the profile:

RouteTerrainProfile? terrainProfile = route.terrainProfile;

if (terrainProfile != null) {
double minElevation = terrainProfile.minElevation;
double maxElevation = terrainProfile.maxElevation;
int minElevDist = terrainProfile.minElevationDistance;
int maxElevDist = terrainProfile.maxElevationDistance;
double totalUp = terrainProfile.totalUp;
double totalDown = terrainProfile.totalDown;

// elevation at 100m from the route start
double elevation = terrainProfile.getElevation(100);

for (final section in terrainProfile.roadTypeSections) {
RoadType roadType = section.type;
int startDistance = section.startDistanceM;
}

for (final section in terrainProfile.surfaceSections) {
SurfaceType surfaceType = section.type;
int startDistance = section.startDistanceM;
}

for (final section in terrainProfile.climbSections) {
Grade grade = section.grade;
double slope = section.slope;
int startDistanceM = section.startDistanceM;
int endDistanceM = section.endDistanceM;
}

List<double> categs = [-16, -10, -7, -4, -1, 1, 4, 7, 10, 16];

List<SteepSection> steepSections = terrainProfile.getSteepSections(categs);
for (final section in steepSections) {
int categ = section.categ;
int startDistanceM = section.startDistanceM;
}
}

RoadType values: motorways, stateRoad, road, street, cycleway, path, singleTrack.

SurfaceType values: asphalt, paved, unpaved, unknown.

Route profile chart
Route profile sections

See the Route Profile example for detailed information.


Retrieve route instructions

Access detailed turn-by-turn instructions and segment information for computed routes.

Each segment represents the route portion between consecutive waypoints and includes its own set of instructions. A route with five waypoints contains four segments, each with distinct instructions.

For public transit routes, segments represent either pedestrian paths or transit sections.

Key RouteInstruction properties:

FieldTypeExplanation
traveledTimeDistanceTimeDistanceTime and distance from the beginning of the route.
remainingTravelTimeDistanceTimeDistanceTime and distance to the end of the route.
coordinatesCoordinatesThe coordinates indicating the location of the instruction.
remainTravelTimeDistToNextWaypointTimeDistanceTime and distance until the next waypoint.
timeDistanceToNextTurnTimeDistanceTime and distance until the next instruction.
turnDetailsTurnDetailsGet full details for the turn.
turnInstructionStringGet textual description for the turn.
roadInfoList<RoadInfo>Get road information.
hasFollowRoadInfoboolCheck is the road has follow road information.
followRoadInstructionStringGet textual description for the follow road information.
countryCodeISOStringGet ISO 3166-1 alpha-3 country code for the navigation instruction.
exitDetailsStringGet the exit route instruction text.
signpostInstructionStringGet textual description for the signpost information.
signpostDetailsSignpostDetailsGet extended signpost details.
roadInfoImgRoadInfoImgGet customizable road image. The user is responsible to check if the image is valid.
turnImgImgGet turn image. The user is responsible to check if the image is valid.
realisticNextTurnImgAbstractGeometryImgGet customizable image for the realistic turn information. The user is resposible to check if the image is valid.
List containing route instructions

Access instruction data using these RouteInstruction methods:

  • turnInstruction: Bear left onto A 5
  • followRoadInstruction: Follow A 5 for 132m
  • traveledTimeDistance.totalDistanceM: 6.2km (after formatting)
  • turnDetails.abstractGeometryImg.getRenderableImageBytes(renderSettings: AbstractGeometryImageRenderSettings(),size: Size(100, 100)): Instruction image or null when invalid