isOnPath method
this method to generate instructions of specific road
Implementation
Future<bool> isOnPath(
Road road,
LngLat currentLocation, {
double tolerance = 0.1,
}) async {
var polyline = road.polyline;
if (road.polyline == null && road.polylineEncoded == null) {
throw Exception(
'we cannot provide next instruction where [polylines] or/and [polylineEncoded] in roads is null');
} else if (road.polyline == null && road.polylineEncoded != null) {
polyline = PrivateRoad.decodePoylinesGeometry(road.polylineEncoded!);
}
final location = currentLocation.alignWithPrecision(precision: 5);
final indexOfNextLocation = indexOfLocationFromRoad(
location,
polyline!,
tolerance: tolerance,
);
if (indexOfNextLocation == -1 ||
indexOfNextLocation > polyline.length - 1) {
return false;
}
return true;
}