buildRoute method
Build the Route Used for the Navigation
wayPoints
must not be null. A collection of WayPoint(longitude,
latitude and name). Must be at least 2 or at most 25. Cannot use
drivingWithTraffic mode if more than 3-waypoints.
options
options used to generate the route and used while navigating
Implementation
Future<bool> buildRoute({
required List<WayPoint> wayPoints,
MapBoxOptions? options,
}) async {
assert(wayPoints.length > 1, 'Error: WayPoints must be at least 2');
if (Platform.isIOS && wayPoints.length > 3 && options?.mode != null) {
assert(
options!.mode != MapBoxNavigationMode.drivingWithTraffic,
'''
Error: Cannot use drivingWithTraffic Mode
when you have more than 3 Stops
''',
);
}
final pointList = <Map<String, Object?>>[];
for (var i = 0; i < wayPoints.length; i++) {
final wayPoint = wayPoints[i];
assert(wayPoint.name != null, 'Error: waypoints need name');
assert(wayPoint.latitude != null, 'Error: waypoints need latitude');
assert(wayPoint.longitude != null, 'Error: waypoints need longitude');
final pointMap = <String, dynamic>{
'Order': i,
'Name': wayPoint.name,
'Latitude': wayPoint.latitude,
'Longitude': wayPoint.longitude,
};
pointList.add(pointMap);
}
var i = 0;
final wayPointMap = {for (var e in pointList) i++: e};
var args = <String, dynamic>{};
if (options != null) args = options.toMap();
args['wayPoints'] = wayPointMap;
_routeEventSubscription = _streamRouteEvent!.listen(_onProgressData);
return _methodChannel
.invokeMethod('buildRoute', args)
.then((dynamic result) => result as bool);
}