buildRoute method
Future<bool>
buildRoute({
- required List<
WayPoint> wayPoints, - MapOptions? options,
- DrivingProfile profile = DrivingProfile.drivingTraffic,
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,
MapOptions? options,
DrivingProfile profile = DrivingProfile.drivingTraffic}) async {
assert(wayPoints.length > 1);
if (Platform.isIOS && wayPoints.length > 3 && options?.mode != null) {
assert(options!.mode != MapNavigationMode.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 = {for (var e in pointList) i++: e};
Map<String, dynamic> args = <String, dynamic>{};
if (options != null) args = options.toMap();
args["wayPoints"] = wayPointMap;
args['profile'] = profile.getValue();
return await _methodChannel
.invokeMethod(MethodChannelEvent.buildRoute, args)
.then<bool>((dynamic result) => result);
}