25-4/14/1
This commit is contained in:
@@ -104,6 +104,8 @@ class LocationController extends GetxController {
|
||||
return 'Cairo';
|
||||
}
|
||||
|
||||
int _insertCounter = 0;
|
||||
|
||||
Future<void> startLocationUpdates() async {
|
||||
if (box.read(BoxName.driverID) != null) {
|
||||
if (location == null) {
|
||||
@@ -117,49 +119,59 @@ class LocationController extends GetxController {
|
||||
Get.find<CaptainWalletController>().totalPoints.toString();
|
||||
isActive = Get.find<HomeCaptainController>().isActive;
|
||||
|
||||
if (isActive) {
|
||||
if (double.parse(totalPoints) > -300) {
|
||||
await getLocation();
|
||||
if (myLocation == null) {
|
||||
return;
|
||||
}
|
||||
// 'Latitude: ${myLocation.latitude}, Longitude: ${myLocation.longitude}');
|
||||
if (isActive && double.parse(totalPoints) > -300) {
|
||||
await getLocation();
|
||||
if (myLocation == null) return;
|
||||
|
||||
String area =
|
||||
getLocationArea(myLocation.latitude, myLocation.longitude);
|
||||
String area =
|
||||
getLocationArea(myLocation.latitude, myLocation.longitude);
|
||||
|
||||
if (box.read(BoxName.driverID) != null) {
|
||||
await CRUD().post(
|
||||
link: box.read(BoxName.serverChosen) +
|
||||
'/ride/location/add.php',
|
||||
payload: {
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
'latitude': myLocation.latitude.toString(),
|
||||
'longitude': myLocation.longitude.toString(),
|
||||
'heading': heading.toString(),
|
||||
'speed': (speed * 3.6).toStringAsFixed(1),
|
||||
'distance': totalDistance == 0 && (speed * 3.6) < 5
|
||||
? '0.0'
|
||||
: totalDistance < 7
|
||||
? totalDistance.toStringAsFixed(3)
|
||||
: totalDistance.toStringAsFixed(1),
|
||||
'status': box.read(BoxName.statusDriverLocation) ?? 'off',
|
||||
});
|
||||
final payload = {
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
'latitude': myLocation.latitude.toString(),
|
||||
'longitude': myLocation.longitude.toString(),
|
||||
'heading': heading.toString(),
|
||||
'speed': (speed * 3.6).toStringAsFixed(1),
|
||||
'distance': totalDistance == 0 && (speed * 3.6) < 5
|
||||
? '0.0'
|
||||
: totalDistance < 7
|
||||
? totalDistance.toStringAsFixed(3)
|
||||
: totalDistance.toStringAsFixed(1),
|
||||
'status': box.read(BoxName.statusDriverLocation) ?? 'off',
|
||||
};
|
||||
|
||||
Get.find<HomeCaptainController>()
|
||||
.mapHomeCaptainController
|
||||
?.animateCamera(
|
||||
CameraUpdate.newLatLng(
|
||||
LatLng(
|
||||
Get.find<LocationController>().myLocation.latitude,
|
||||
Get.find<LocationController>().myLocation.longitude,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
// 🔁 كل 5 ثواني - تحديث الموقع
|
||||
await CRUD().post(
|
||||
link:
|
||||
box.read(BoxName.serverChosen) + '/ride/location/update.php',
|
||||
payload: payload,
|
||||
);
|
||||
|
||||
// 📍 كل 60 ثانية - إدخال جديد
|
||||
_insertCounter++;
|
||||
if (_insertCounter >= 12) {
|
||||
_insertCounter = 0;
|
||||
await CRUD().post(
|
||||
link: box.read(BoxName.serverChosen) + '/ride/location/add.php',
|
||||
payload: payload,
|
||||
);
|
||||
}
|
||||
|
||||
// 🔄 تحديث الكاميرا
|
||||
Get.find<HomeCaptainController>()
|
||||
.mapHomeCaptainController
|
||||
?.animateCamera(
|
||||
CameraUpdate.newLatLng(
|
||||
LatLng(
|
||||
Get.find<LocationController>().myLocation.latitude,
|
||||
Get.find<LocationController>().myLocation.longitude,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
print('Location update error: $e');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user