buildRoute method

Future<bool> buildRoute({
  1. required List<LatLng> waypoints,
  2. MapOptions? options,
  3. DrivingProfile profile = DrivingProfile.drivingTraffic,
})

Build the Route Used for the Navigation

waypoints must not be null. A collection of LatLng(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<LatLng> 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 latLng = waypoints[i];

    final pointMap = <String, dynamic>{
      "Order": i,
      "Name": i.toString(),
      "Latitude": latLng.latitude,
      "Longitude": latLng.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);
}