startNavigation method

Future startNavigation(
  1. {List<WayPoint> wayPoints,
  2. MapBoxOptions options,
  3. RouteResponse route}
)

Implementation

Future startNavigation(
    {List<WayPoint> wayPoints, MapBoxOptions options, BaatoRoute.RouteResponse route}) async {
  assert(wayPoints != null);
  assert(wayPoints.length > 1);
  if (Platform.isIOS && wayPoints.length > 3) {
    assert(options.mode != BaatoNavigationMode.car,
    "Error: Cannot use drivingWithTraffic Mode when you have more than 3 Stops");
  }
  var pointList = List<Map<String, Object>>();

  for (int i = 0; i < wayPoints.length; i++) {
    var wayPoint = wayPoints[i];
    assert(wayPoint != null);
    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);

  var args = options.toMap();
  args["wayPoints"] = wayPointMap;
  if(route != null) {

    // debugPrint();
    //
    // var rts = json.encode(route);
    // // debugPrint(rts);
    // debugPrint(JsonEncoder.withIndent(' ').convert(toBrsJson(route)));
    args["route"] = JsonEncoder.withIndent(' ').convert(toBrsJson(route));
    // print(args["route"]);
  }
  currentLegIndex = 0;
  legsCount = wayPoints.length - 1;

  _routeEventSubscription = _streamRouteEvent.listen(_onProgressData);
  await _methodChannel
      .invokeMethod('startNavigation', args)
      .then<String>((dynamic result) => result);
}