Usage

The NextBillion.ai Flutter Navigation SDK empowers you to integrate advanced navigation capabilities into your Flutter application. Follow these steps to utilize the SDK effectively:

NB Maps

If you need to use Map-related functions, such as displaying a Map widget, please refer to our Flutter Maps Plugin Documentation.

Fetch routes

To request routes, use RouteRequestParams with NBNavigation. For supported parameters, please refer to Navigation API documentation.

Create the RouteRequestParams object with the required parameters:

1
RouteRequestParams requestParams = RouteRequestParams(
2
origin: origin,
3
destination: dest,
4
// waypoints: [waypoint1, waypoint2],
5
// language: 'en',
6
// alternatives: true,
7
// overview: ValidOverview.simplified,
8
// avoid: [SupportedAvoid.toll, SupportedAvoid.ferry],
9
// option: SupportedOption.flexible,
10
// unit: SupportedUnits.imperial,
11
// mode: ValidModes.car,
12
// geometryType: SupportedGeometry.polyline,
13
);

Following is a list of all the supported parameters and their details:

ParameterRequiredTypeFormat & UsageDescription
originYesLatLng

Format: Latitude, Longitude


Usage: LatLng(34.052235, -118.243683)

The starting point coordinates for the route request.

destinationYesLatLng

Format: Latitude, Longitude


Usage: LatLng(40.712776, -74.005974)

The ending point coordinates for the route request.

modeNoValidModes

Usage: ValidModes.car (default)
ValidModes.truck, ValidModes.bike, ValidModes.motorcycle

Specifies the primary mode of transportation for the route. When using "truck", "bike", or "motorcycle", option must be set to SupportedOption.flexible.

optionNoSupportedOption

Usage: SupportedOption.fast (default)

SupportedOption.flexible

Route calculation option. "flexible" offers customizable features for advanced navigation.

routeTypeNoRouteType

Usage: RouteType.fastest (default)

RouteType.shortest

Type of route to calculate. shortest is only available when option=SupportedOption.flexible.

alternativesNobool

Default: false

Whether to return alternative routes. If true, up to two alternatives may be returned.

altCountNoint

e.g., 2

Number of alternative routes to request.

avoidTypeNoList<String>

Allowed Values: "toll", "ferry", "highway", "sharp_turn", "service_road", "left_turn", "right_turn", "bbox", "geofence_id", "none"


Special formats: bbox: min_lat, min_lng, max_lat, max_lng


Multiple bboxes usage: bbox: 34.0635, -118.2547, 34.0679, -118.2478 | bbox:34.0521, -118.2342, 34.0478, -118.2437

Types of road segments to avoid during route calculation. Use a | (pipe) operator to add multiple values. Values "toll", "ferry", "highway" and "none" can be used with either of the SupportedOption.fast or SupportedOption.flexible. All other values require option=SupportedOption.flexible to be set.

languageNoString

"en" (default)

Language for returning turn-by-turn text instructions. This parameter accepts two-lettered ISO 639-1 codes to identify the language for instructions.

unitNoSupportedUnits

Usage: SupportedUnits.metric (default),

SupportedUnits.imperial

Unit of measurement for route distances.

overviewNoValidOverview

Usage: ValidOverview.full (default),

ValidOverview.simplified, ValidOverview.none

Level of detail for returned route geometry.

geometryNoSupportedGeometry

Usage: SupportedGeometry.polyline, SupportedGeometry.polyline6 (default)

Encoding format of route geometry to be returned.

waypointsNoList<LatLng>

Usage: [LatLng(34.052235, -118.243683), LatLng(35.052235, -119.243683)]

List of intermediate points to visit along the route (non-snapped coordinates).

approachesNoList<SupportedApproaches>

Usage: SupportedApproaches.unrestricted (default), SupportedApproaches.curb

Specifies from which side of the road to approach waypoints. Must match waypoints length if provided.

truckWeightNoint

Format: Range: 1-100000 (kg)

Total weight of the truck including trailers and cargo. Only effective when mode=ValidModes.truck and option=SupportedOption.flexible.

truckSizeNoList<int>

Format: [height, width, length] in cm (Maximum values: [1000, 5000, 5000])

Truck dimensions in centimeters. Only effective when mode=ValidModes.truck and option=SupportedOption.flexible.

hazmatTypeNo

List<SupportedHazmatType>

Usage: SupportedHazmatType.general, SupportedHazmatType.circumstantial, SupportedHazmatType.explosive, SupportedHazmatType.harmfulToWater

Specifies hazardous material type to avoid unsuitable roads. Only effective when mode=ValidModes.truck and option=SupportedOption.flexible.

crossBorderNobool

true (default), false

Whether to allow crossing international borders. Only available in North America.

truckAxleLoadNonum

e.g., 10.5 (tonnes)

Total load per axle (including trailers and cargo weight). Only effective when mode=ValidModes.truck.

allowNoString

"taxi", "hov"

Special route types to allow (e.g., taxi or HOV routes).

Fetch routes

Use NBNavigation.fetchRoute() to fetch routes with the specified requestParams, and get the route response DirectionsRouteResponse, the response will contain the route info.

1
DirectionsRouteResponse response = await NBNavigation.fetchRoute(requestParams);

Draw routes

After obtaining the routes, you can draw routes on the map view using NavNextBillionMap. Ensure you have the NextbillionMapController created in the onMapCreated callback of the NBMap widget. Refer to Flutter Maps Plugin documentation for more information.

Create NavNextBillionMap with NextbillionMapController in NBMap widget’s onStyleLoaded callback:

1
void _onMapCreated(NextbillionMapController controller) {
2
this.controller = controller;
3
}
4
5
void _onStyleLoaded() async {
6
if (controller != null) {
7
navNextBillionMap = await NavNextBillionMap.create(controller!);
8
}
9
}

Draw routes

Once you have the NavNextBillionMap instance, draw the routes on the map view:

1
await navNextBillionMap.drawRoute(routes);

Clear routes

To remove the drawn routes from the map view, use clearRoute():

1
navNextBillionMap.clearRoute();

Toggle Alternative Route Visibility

You can toggle the visibility of alternative routes on the map:

1
navNextBillionMap.toggleAlternativeVisibilityWith(visible);

Toggle Route DurationSymbol Visibility

Toggle the visibility of the route duration symbol on the map:

1
navNextBillionMap.toggleDurationSymbolVisibilityWith(visible);

Add RouteSelected Listener.

You can add route switching listener in the onMapClick callback:

1
onMapClick(Point<double> point, LatLng coordinates) {
2
navNextBillionMap.addRouteSelectedListener(coordinates, (selectedRouteIndex) {})
3
}

Start navigation

To initiate navigation, use NavigationLauncherConfig. The following properties can be configured as per your preference:

  • route: The selected route for directions

  • routes: A list of available routes

  • themeMode: The theme mode for navigation UI, default value is system

    • system: follows system theme mode

    • light: applies light theme

    • dark: applies dark theme

  • locationLayerRenderMode: The rendering mode for the location layer, default value is LocationLayerRenderMode.GPS.

  • shouldSimulateRoute: Whether to simulate the route during navigation, default value is false.

  • enableDissolvedRouteLine: Whether to enable the dissolved route line during navigation, default value is true.

  • navigationMapStyleUrl: Indicates the map style in the Navigation view. Its priority is higher than the navViewMapStyle of (CustomNavigationViewLight, CustomNavigationViewDark) set in the styles.xml for Android and the mapStyleURL of (customDayStyle, customNightStyle) set in the AppDelegate for iOS.

  • useCustomNavigationStyle: Indicates whether to enable the custom style defined in styles.xml for Android (CustomNavigationViewLight, CustomNavigationViewDark) AppDelegate for iOS (customDayStyle, customNightStyle)

  • showArriveDialog: Indicates whether to show the arrival dialog. If set to true, the arrive dialog will be shown when the user arrives at the waypoints or destination. If set to false, the arrive dialog will not be shown when the user arrives at the waypoints or destination. This property is only available for call [NBNavigation.startNavigation] to launch the navigation. It is not available for [NBNavigationView].If you want to show the arrive dialog in [NBNavigationView], you need to customize the dialog by yourself in the [NBNavigationView.onArriveAtWaypoint].

  • showSpeedometer : Indicates whether to show the speedometer. If set to true, the speedometer will be shown during navigation.If set to false, the speedometer will not be shown during navigation.

1
NavigationLauncherConfig config = NavigationLauncherConfig(route: routes.first, routes: routes, shouldSimulateRoute: true);
2
3
NBNavigation.startNavigation(config);

Launch Embedded NavigationView

NBNavigationView is a customizable navigation view widget designed to provide seamless navigation experiences in your Flutter application. It offers various configuration options to cater to different navigation requirements, such as theme modes, location layer render modes, and custom styles.

  • Important : If you want to use the NavigationView, you need to make the MainActivity extend FlutterFragmentActivity instead of FlutterActivity in the Android project.
1
class MainActivity: FlutterFragmentActivity() {
2
}

NBNavigationView Widget

1
const NBNavigationView({
2
super.key,
3
required this.navigationOptions,
4
this.onNavigationViewReady,
5
this.onProgressChange,
6
this.onNavigationCancelling,
7
this.onArriveAtWaypoint,
8
this.onRerouteFromLocation,
9
});

Parameters

By utilizing the NavigationLauncherConfig class, you can customize the navigation experience to meet your specific needs, from theme settings to location layer modes and custom styles.

  • navigationOptions (required): This parameter provides the necessary configuration for the navigation view.
  • onNavigationViewReady: A callback that is triggered when the navigation view is ready.
  • onProgressChange: A callback that is triggered when there is a change in the navigation progress.
  • onNavigationCancelling: A callback that is triggered when navigation is being canceled.
  • onArriveAtWaypoint: A callback that is triggered when arriving at a waypoint.
  • onRerouteFromLocation: A callback that is triggered when rerouting from a specific location.

Example Usage

1
NBNavigationView(
2
navigationOptions: NavigationLauncherConfig(
3
route: selectedRoute,
4
routes: allRoutes,
5
themeMode: NavigationThemeMode.system,
6
),
7
onNavigationViewReady: (controller) {
8
// Handle navigation view ready
9
},
10
onProgressChange: (progress) {
11
// Handle progress change
12
},
13
onNavigationCancelling: () {
14
// Handle navigation canceling
15
},
16
onArriveAtWaypoint: (waypoint) {
17
// Handle arriving at waypoint
18
},
19
onRerouteFromLocation: (location) {
20
// Handle rerouting from location
21
},
22
);
documentation image

© 2025 NextBillion.ai all rights reserved.