This commit is contained in:
Hamza-Ayed
2023-09-17 18:42:51 +03:00
parent 2be93e8267
commit 5f402a0b65
17 changed files with 359 additions and 146 deletions

View File

@@ -30,6 +30,7 @@ class MapController extends GetxController {
LatLng mydestination = const LatLng(32.115295, 36.064773);
final List<LatLng> polylineCoordinates = [];
List<LatLng> carsLocationByPassenger = [];
List<LatLng> driverCarsLocationToPassengerAfterApplied = [];
BitmapDescriptor markerIcon = BitmapDescriptor.defaultMarker;
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
double height = 150;
@@ -57,6 +58,7 @@ class MapController extends GetxController {
late LatLng northeast;
List<CarLocationModel> carLocations = <CarLocationModel>[];
var dataCarsLocationByPassenger;
var datadriverCarsLocationToPassengerAfterApplied;
CarLocation? nearestCar;
late Timer markerReloadingTimer;
bool shouldFetch = true; // Flag to determine if fetch should be executed
@@ -226,7 +228,7 @@ class MapController extends GetxController {
void timerEnded() async {
print('Timer ended');
// refuseOrder();
runEvery50SecondsUntilConditionMet();
isCancelRidePageShown = false;
update();
}
@@ -437,6 +439,59 @@ class MapController extends GetxController {
}
}
Future getDriverCarsLocationToPassengerAfterApplied() async {
driverCarsLocationToPassengerAfterApplied = [];
var res = await CRUD().get(
link: AppLink.getDriverCarsLocationToPassengerAfterApplied,
payload: {
'driver_id': dataCarsLocationByPassenger['message'][0]['driver_id']
});
datadriverCarsLocationToPassengerAfterApplied = jsonDecode(res);
driverCarsLocationToPassengerAfterApplied.add(LatLng(
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['latitude']),
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['longitude'])));
update();
}
Future runEvery50SecondsUntilConditionMet() async {
// Calculate the duration of the trip in minutes.
double tripDurationInMinutes = duration1 / 60;
int loopCount = tripDurationInMinutes.ceil();
// If the trip duration is less than or equal to 50 minutes, then break the loop.
for (var i = 0; i < loopCount; i++) {
// Wait for 50 seconds.
await Future.delayed(const Duration(
seconds:
50)); // Run the `getDriverCarsLocationToPassengerAfterApplied()` function.
await getDriverCarsLocationToPassengerAfterApplied();
reloadMarkerDriverCarsLocationToPassengerAfterApplied();
}
}
void reloadMarkerDriverCarsLocationToPassengerAfterApplied() {
// Clear existing markers
markers.clear();
for (var item in driverCarsLocationToPassengerAfterApplied) {
final marker = Marker(
infoWindow: InfoWindow(title: '${item.latitude} minutes'),
markerId: MarkerId(item.toString()),
position: LatLng(item.latitude, item.longitude),
);
markers.add(marker);
update();
mapController?.animateCamera(
CameraUpdate.newLatLng(LatLng(item.latitude, item.longitude)));
update();
} // Update the map with the new markers
}
LatLngBounds calculateBounds(
double centerLat, double centerLng, double radius) {
// double radius = 4000; // 10 km in meters