This commit is contained in:
Hamza-Ayed
2024-11-12 00:45:23 +02:00
parent 213c2724aa
commit bf8a29b814
8 changed files with 156 additions and 81 deletions

View File

@@ -1780,7 +1780,7 @@ class MapPassengerController extends GetxController {
// getCarForFirstConfirm(carType);
confirmRideForAllDriverAvailable();
// delayAndFetchRideStatusForAllDriverAvailable(rideId);
} else if (rideStatusDelayed == 'Apply') {
} else if (rideStatusDelayed == 'Apply' || statusRide == 'Apply') {
Log.print('rideStatusDelayed == Apply: ${rideStatusDelayed}');
// todo play sound
Get.find<AudioRecorderController>()
@@ -3364,7 +3364,7 @@ class MapPassengerController extends GetxController {
reloadCount++;
Log.print('reloadCount: $reloadCount');
if (!rideConfirm) {
if (rideConfirm == false) {
clearMarkersExceptStartEnd();
// _smoothlyUpdateMarker();
// startCarLocationSearch(box.read(BoxName.carType));
@@ -3391,59 +3391,122 @@ class MapPassengerController extends GetxController {
late Duration durationFromDriverToPassenger;
double nearestDistance = double.infinity;
Future<CarLocation?> getNearestDriverByPassengerLocation() async {
if (polyLines.isEmpty || data.isEmpty) {
return null; // Early return if data is empty
}
// Future<CarLocation?> getNearestDriverByPassengerLocation() async {
// if (polyLines.isEmpty || data.isEmpty) {
// return null; // Early return if data is empty
// }
// if (!rideConfirm) {
// if (dataCarsLocationByPassenger != 'failure') {
// if (dataCarsLocationByPassenger != null) {
// if (dataCarsLocationByPassenger['message'].length > 0) {
// double nearestDistance = double
// .infinity; // Initialize nearest distance to a large number
// CarLocation? nearestCar;
// for (var i = 0;
// i < dataCarsLocationByPassenger['message'].length;
// i++) {
// var carLocation = dataCarsLocationByPassenger['message'][i];
// // Calculate the distance between passenger's location and current driver's location
// final distance = Geolocator.distanceBetween(
// passengerLocation.latitude,
// passengerLocation.longitude,
// double.parse(carLocation['latitude']),
// double.parse(carLocation['longitude']),
// );
// // Calculate duration assuming an average speed of 25 km/h (adjust as needed)
// int durationToPassenger =
// (distance * 25 * (1000 / 3600)).round(); // 25 km/h in m/s
// // Update the UI with the distance and duration for each car
// update();
// // If this distance is smaller than the nearest distance found so far, update nearestCar
// if (distance < nearestDistance) {
// nearestDistance = distance;
// nearestCar = CarLocation(
// distance: distance,
// duration: durationToPassenger.toDouble(),
// id: carLocation['driver_id'],
// latitude: double.parse(carLocation['latitude']),
// longitude: double.parse(carLocation['longitude']),
// );
// // Update the UI with the nearest driver
// update();
// }
// }
// // Return the nearest car found
// return nearestCar;
// }
// }
// }
// }
// // Return null if no drivers are found or if ride is confirmed
// return null;
// }
Future<CarLocation?> getNearestDriverByPassengerLocation() async {
// if (polyLines.isEmpty && data.isEmpty) {
// return null; // Early return if data is empty
// }
// Log.print('rideConfirm: ${rideConfirm}');
// Log.print('dataCarsLocationByPassenger: ${dataCarsLocationByPassenger}');
if (!rideConfirm) {
if (dataCarsLocationByPassenger != 'failure') {
if (dataCarsLocationByPassenger != null) {
if (dataCarsLocationByPassenger['message'].length > 0) {
double nearestDistance = double
.infinity; // Initialize nearest distance to a large number
CarLocation? nearestCar;
if (dataCarsLocationByPassenger != null &&
dataCarsLocationByPassenger['message'] != null &&
dataCarsLocationByPassenger['message'].length > 0) {
double nearestDistance =
double.infinity; // Initialize nearest distance
CarLocation? nearestCar;
for (var i = 0;
i < dataCarsLocationByPassenger['message'].length;
i++) {
var carLocation = dataCarsLocationByPassenger['message'][i];
for (var i = 0;
i < dataCarsLocationByPassenger['message'].length;
i++) {
var carLocation = dataCarsLocationByPassenger['message'][i];
Log.print('carLocation: ${carLocation}');
// Calculate the distance between passenger's location and current driver's location
final distance = Geolocator.distanceBetween(
passengerLocation.latitude,
passengerLocation.longitude,
double.parse(carLocation['latitude']),
double.parse(carLocation['longitude']),
// Calculate distance between passenger's location and current driver's location
final distance = Geolocator.distanceBetween(
passengerLocation.latitude,
passengerLocation.longitude,
double.parse(carLocation['latitude']),
double.parse(carLocation['longitude']),
);
// Calculate duration assuming an average speed of 25 km/h (adjust as needed)
int durationToPassenger = (distance * 25 * (1000 / 3600)).round();
Log.print('distance: ${distance}');
Log.print('durationToPassenger: ${durationToPassenger}');
// Update the UI with the distance and duration for each car
update();
// If this distance is smaller than the nearest distance found so far, update nearestCar
if (distance < nearestDistance) {
nearestDistance = distance;
nearestCar = CarLocation(
distance: distance,
duration: durationToPassenger.toDouble(),
id: carLocation['driver_id'],
latitude: double.parse(carLocation['latitude']),
longitude: double.parse(carLocation['longitude']),
);
// Calculate duration assuming an average speed of 25 km/h (adjust as needed)
int durationToPassenger =
(distance * 25 * (1000 / 3600)).round(); // 25 km/h in m/s
// Update the UI with the distance and duration for each car
Log.print('nearestCar: ${nearestCar}');
// Update the UI with the nearest driver
update();
// If this distance is smaller than the nearest distance found so far, update nearestCar
if (distance < nearestDistance) {
nearestDistance = distance;
nearestCar = CarLocation(
distance: distance,
duration: durationToPassenger.toDouble(),
id: carLocation['driver_id'],
latitude: double.parse(carLocation['latitude']),
longitude: double.parse(carLocation['longitude']),
);
// Update the UI with the nearest driver
update();
}
}
// Return the nearest car found
return nearestCar;
}
// Return the nearest car found
return nearestCar;
}
}
}