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);
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");
}
List<Map<String, Object?>> pointList = [];
for (int i = 0; i < wayPoints.length; i++) {
var wayPoint = wayPoints[i];
assert(wayPoint.name != null);
assert(wayPoint.latitude != null);
assert(wayPoint.longitude != null);
final pointMap = <String, dynamic>{
"Order": i,
"Name": wayPoint.name,
"Latitude": wayPoint.latitude,
"Longitude": wayPoint.longitude,
};
pointList.add(pointMap);
}
var i = 0;
var wayPointMap =
Map.fromIterable(pointList, key: (e) => i++, value: (e) => e);
Map<String, dynamic> args = Map<String, dynamic>();
if (options != null) args = options.toMap();
args["wayPoints"] = wayPointMap;
_routeEventSubscription = _streamRouteEvent!.listen(_onProgressData);
return await _methodChannel
.invokeMethod('buildRoute', args)
.then<bool>((dynamic result) => result);
}