isOnPath method

bool isOnPath(
  1. Route road,
  2. LngLat currentLocation, {
  3. double tolerance = 0.1,
  4. int precision = 5,
})

isOnPath

this method to generate instructions of specific road

Implementation

bool isOnPath(
  Route road,
  LngLat currentLocation, {
  double tolerance = 0.1,
  int precision = 5,
}) {
  var polyline = road.polyline;
  if (road.polyline.isNullOrEmpty && road.polylineEncoded == null) {
    throw Exception(
      'we cannot provide next instruction where [polylines] or/and [polylineEncoded]  in roads is null',
    );
  } else if (road.polyline.isNullOrEmpty && road.polylineEncoded != null) {
    polyline = road.polylineEncoded?.decodeGeometry(
      precision: precision,
    );
  }
  final location = currentLocation.alignWithPrecision(precision: precision);

  final indexOfNextLocation = indexOfLocationFromRoad(
    location,
    polyline!,
    tolerance: tolerance,
  );
  if (indexOfNextLocation == -1 ||
      indexOfNextLocation > polyline.length - 1) {
    return false;
  }
  return true;
}