Navigation | Mobile SDK | 2GIS Documentation
Flutter SDK

Navigation

You can add a turn-by-turn navigation to your app using the ready-to-use interface components and a NavigationManager object:

import 'package:dgis_mobile_sdk_full/dgis.dart' as sdk;

final sdk.Context sdkContext = sdk.DGis.initialize();
final sdk.NavigationManager navigationManager = sdk.NavigationManager(sdkContext);

Add a location marker to the map and connect the map with a NavigationManager object.

import 'package:dgis_mobile_sdk_full/dgis.dart' as sdk;

final sdk.MyLocationMapObjectSource locationSource = sdk.MyLocationMapObjectSource(sdkContext);
map.addSource(locationSource);

navigationManager.mapManager.addMap(map);

You can start navigation in one of the three modes: free-drive, turn-by-turn, or simulated navigation.

Additional navigation settings can be changed using the properties of a NavigationManager object.

In free-drive mode, no route will be displayed on the map, but the user will still be informed about speed limits, traffic cameras, incidents, and road closures.

To start navigation in this mode, call the startFreeRoam() method without parameters.

import 'package:dgis_mobile_sdk_full/dgis.dart' as sdk;

final sdk.Context sdkContext = sdk.DGis.initialize();
final sdk.NavigationManager navigationManager = sdk.NavigationManager(sdkContext);

navigationManager.startFreeRoam();

In turn-by-turn mode, a route will be displayed on the map, and the user will receive navigation instructions as they move along the route.

To start navigation in this mode, call the start() method and specify a RouteBuildOptions object – arrival coordinates and route settings.

import 'package:dgis_mobile_sdk_full/dgis.dart' as sdk;

final routeBuildOptions = sdk.RouteBuildOptions(
    finishPoint: sdk.RouteSearchPoint(
        coordinates: sdk.GeoPoint(
            latitude: sdk.Latitude(55.757670),
            longitude: sdk.Longitude(37.660160),
        ),
    ),
    routeSearchOptions: sdk.RouteSearchOptions.car(
        sdk.CarRouteSearchOptions(),
    ),
);

navigationManager.start(routeBuildOptions);

Additionally, when calling the start() method, you can specify a TrafficRoute object – a complete route object for navigation (see Building a route). In this case, a NavigationManager object will use the specified route instead of building a new one.

navigationManager.start(routeBuildOptions, trafficRoute);

In this mode, a NavigationManager object will not track the current location of the device. Instead, it will simulate a movement along the specified route. This mode is useful for debugging.

To use this mode, call the startSimulation() method and specify a RouteBuildOptions object (the route settings) and a TrafficRoute object (the route itself).

You can change the speed of the simulated movement using the SimulationSettings.speedMode property (specified in meters per second).

navigationManager.simulationSettings.speedMode = sdk.SimulationSpeedMode.overSpeed(
  sdk.SimulationAutoWithOverSpeed(10)
);

navigationManager.startSimulation(routeBuildOptions, trafficRoute);

To stop the simulation, call the stop() method:

navigationManager.stop();

To display traffic on the map, add a TrafficSource data source.

final sdk.TrafficSource trafficSource = sdk.TrafficSource(sdkContext);
map.addSource(trafficSource);

  

The SDK provides the ability to build routes within certain buildings for which there are floor plans. For example, you can build a route to a specific store in a mall, make a complex route between several points, etc.

This type of navigation is included in the Full SDK, but has a number of limitations:

  • Can only be activated in pedestrian navigation mode.
  • Due to the way modern positioning systems work, the ability to determine the position inside buildings is severely limited. When the system determines that the device has entered the limits of the building, the geopositioning tracking and its display will be disabled, leaving only the constructed route and recommendations for the passage.

Creating a route follows the principles described in Turn-by-turn mode with a few important additions. Let's take an example:

import 'package:dgis_mobile_sdk_full/dgis.dart' as sdk;

// RouteBuildOptions object is also required
final routeBuildOptions = sdk.RouteBuildOptions(
    finishPoint: sdk.RouteSearchPoint(
        coordinates: sdk.GeoPoint(
            latitude: sdk.Latitude(55.757670),
            longitude: sdk.Longitude(37.660160),
        ),
        objectId: ..., // You can get it from DgisMapObject
        levelId: ..., // You can get it from DirectoryObject or RenderedObjectInfo
    ),
    // The type of routeSearchOptions is PedestrianRouteSearchOptions
    routeSearchOptions: sdk.RouteSearchOptions.pedestrian(
        sdk.PedestrianRouteSearchOptions(),
    ),
);

When creating a route endpoint RouteSearchPoint, the objectId and levelId parameters are mandatory.

You can use the standard SDK features to detect when a user enters the indoor navigation mode by subscribing to an indoorChannel channel. This channel can be obtained from NavigationManager.indoorDetector.