Skip to main content
Before you can start a navigation session, you need to calculate a route between two or more locations. This guide will show you how to use the Journey SDK to plan a route and display it on the map and start a subsequent navigation session.

Planning a route

To plan a route, you need to use the TomtomFlutterRoutePlannerManager class. This class provides a method to calculate a route between two or more locations. The following example shows how to calculate a route between two locations:
import 'package:tomtom_flutter_route_planner/tomtom_flutter_route_planner.dart';

final TomtomFlutterRoutePlannerManager _routePlannerManager =
    TomtomFlutterRoutePlannerManager.instance;

final costModel = FlutterCostModel(
  routeType: FlutterRouteType.fast,
  avoidOptions: FlutterAvoidOptions(
    avoids: [FlutterAvoidTypeWrapper(type: FlutterAvoidType.carpools)],
  ),
);

final guidanceOptions = FlutterGuidanceOptions(
  instructionType: FlutterInstructionType.tagged,
  language: FlutterRoutePlannerLocale(
    identifier: 'en-US',
  ),
  roadShieldReferences: FlutterRoadShieldReferences.all,
  announcementPoints: FlutterAnnouncementPoints.all,
  phoneticsType: FlutterInstructionPhoneticsType.ipa,
  extendedSections: FlutterExtendedSections.all,
  progressPoints: FlutterProgressPoints.all,
  guidanceVersion: FlutterOnlineApiVersion.v1,
);

final alternativeRoutesOptions =
    FlutterAlternativeRoutesOptions(maxAlternatives: 3);

final routePlans = await _routePlannerManager.planRoutes(
  FlutterRoutePlanningOptions(
    guidanceOptions: guidanceOptions,
    mode: FlutterRouteInformationMode.complete,
    vehicle: FlutterVehicle(type: FlutterVehicleType.car),
    alternativeRoutesOptions: alternativeRoutesOptions,
    costModel: costModel,
    itinerary: FlutterItinerary(
      origin: FlutterItineraryPoint(
        id: 'origin',
        place: FlutterPlace(
          name: 'Home',
          coordinate: FlutterRoutePlannerLatLng(
            latitude: 37.78341291804448,
            longitude: -122.41449268056682,
          ),
        ),
      ),
      destination: FlutterItineraryPoint(
        id: 'destination',
        place: FlutterPlace(
          name: 'Work',
          coordinate: FlutterRoutePlannerLatLng(
            latitude: 37.68193721015795,
            longitude: -122.47145630870126,
          ),
        ),
      ),
    ),
  ),
);
In this example, we calculate a route between two locations in San Francisco.

Displaying it on a map

After calculating your route plans, you can display one or more routes on a map.
import 'package:tomtom_flutter_map/tomtom_flutter_map.dart';
import 'package:tomtom_flutter_navigation/tomtom_flutter_navigation.dart';
import 'package:tomtom_flutter_route_planner/tomtom_flutter_route_planner.dart';

// plot the route plans on the map
await mapManager.showRoutePlans(routePlans);

// zoom to fit all routes in the map
await mapManager.zoomToRoutes(MapManagerZoomToRoutesArguments(padding: 10));

Next steps

After planning a route, you can start a navigation session. Check out the managing navigation guide to learn how to start, update, or adjust a navigation session.