buildAndStartNavigation method

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

Implementation

Future<bool> buildAndStartNavigation(
    {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 wayPoint = waypoints[i];

    final pointMap = <String, dynamic>{
      "Name": i.toString(),
      "Order": i,
      "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.buildAndStartNavigation, args)
      .then<bool>((dynamic result) => result);
}