25-1/13/1-securejordan
This commit is contained in:
@@ -43,25 +43,62 @@ class LocationController extends GetxController {
|
||||
isActive = Get.put(HomeCaptainController()).isActive;
|
||||
}
|
||||
|
||||
// String getLocationArea(double latitude, double longitude) {
|
||||
// if (latitude >= 29.918901 &&
|
||||
// latitude <= 30.198857 &&
|
||||
// longitude >= 31.215009 &&
|
||||
// longitude <= 31.532186) {
|
||||
// return 'Cairo';
|
||||
// } else if (latitude >= 29.904975 &&
|
||||
// latitude <= 30.143372 &&
|
||||
// longitude >= 30.787030 &&
|
||||
// longitude <= 31.215009) {
|
||||
// return 'Giza';
|
||||
// } else if (latitude >= 30.396286 &&
|
||||
// latitude <= 31.654458 &&
|
||||
// longitude >= 29.041139 &&
|
||||
// longitude <= 32.626259) {
|
||||
// return 'Alexandria';
|
||||
// } else {
|
||||
// return 'Cairo';
|
||||
// }
|
||||
// }
|
||||
String getLocationArea(double latitude, double longitude) {
|
||||
if (latitude >= 29.918901 &&
|
||||
latitude <= 30.198857 &&
|
||||
longitude >= 31.215009 &&
|
||||
longitude <= 31.532186) {
|
||||
return 'Cairo';
|
||||
} else if (latitude >= 29.904975 &&
|
||||
latitude <= 30.143372 &&
|
||||
longitude >= 30.787030 &&
|
||||
longitude <= 31.215009) {
|
||||
return 'Giza';
|
||||
} else if (latitude >= 30.396286 &&
|
||||
latitude <= 31.654458 &&
|
||||
longitude >= 29.041139 &&
|
||||
longitude <= 32.626259) {
|
||||
return 'Alexandria';
|
||||
} else {
|
||||
return 'Cairo';
|
||||
final locations = box.read(BoxName.locationName) ?? [];
|
||||
for (final location in locations) {
|
||||
final locationData = location as Map<String, dynamic>;
|
||||
|
||||
// Debugging: Print location data
|
||||
print('Location Data: $locationData');
|
||||
|
||||
// Convert string values to double
|
||||
final minLatitude =
|
||||
double.tryParse(locationData['min_latitude'].toString()) ?? 0.0;
|
||||
final maxLatitude =
|
||||
double.tryParse(locationData['max_latitude'].toString()) ?? 0.0;
|
||||
final minLongitude =
|
||||
double.tryParse(locationData['min_longitude'].toString()) ?? 0.0;
|
||||
final maxLongitude =
|
||||
double.tryParse(locationData['max_longitude'].toString()) ?? 0.0;
|
||||
|
||||
// Debugging: Print converted values
|
||||
// print(
|
||||
// 'Converted Values: minLatitude=$minLatitude, maxLatitude=$maxLatitude, minLongitude=$minLongitude, maxLongitude=$maxLongitude');
|
||||
|
||||
if (latitude >= minLatitude &&
|
||||
latitude <= maxLatitude &&
|
||||
longitude >= minLongitude &&
|
||||
longitude <= maxLongitude) {
|
||||
box.write(BoxName.serverChosen, locationData['server_link']);
|
||||
// Log.print(
|
||||
// 'locationData----server_link: ${locationData['server_link']}');
|
||||
return locationData['name'];
|
||||
}
|
||||
}
|
||||
|
||||
// Default case
|
||||
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
|
||||
return 'Cairo';
|
||||
}
|
||||
|
||||
Future<void> startLocationUpdates() async {
|
||||
@@ -83,50 +120,30 @@ class LocationController extends GetxController {
|
||||
if (myLocation == null) {
|
||||
return;
|
||||
}
|
||||
print(
|
||||
'Latitude: ${myLocation.latitude}, Longitude: ${myLocation.longitude}');
|
||||
// print(
|
||||
// 'Latitude: ${myLocation.latitude}, Longitude: ${myLocation.longitude}');
|
||||
|
||||
String area =
|
||||
getLocationArea(myLocation.latitude, myLocation.longitude);
|
||||
print('Determined Area: $area');
|
||||
|
||||
String endpoint;
|
||||
|
||||
switch (area) {
|
||||
case 'Cairo':
|
||||
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
|
||||
endpoint = AppLink.addCarsLocationCairoEndpoint;
|
||||
break;
|
||||
case 'Giza':
|
||||
box.write(BoxName.serverChosen, AppLink.seferGizaServer);
|
||||
endpoint = AppLink.addCarsLocationGizaEndpoint;
|
||||
break;
|
||||
case 'Alexandria':
|
||||
box.write(
|
||||
BoxName.serverChosen, AppLink.seferAlexandriaServer);
|
||||
endpoint = AppLink.addCarsLocationAlexandriaEndpoint;
|
||||
break;
|
||||
default:
|
||||
endpoint = AppLink.addCarsLocationCairoEndpoint;
|
||||
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
|
||||
}
|
||||
|
||||
Log.print('Final Endpoint: $endpoint');
|
||||
|
||||
if (box.read(BoxName.driverID) != null) {
|
||||
await CRUD().post(link: endpoint, 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).toString(),
|
||||
});
|
||||
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',
|
||||
});
|
||||
|
||||
Get.find<HomeCaptainController>()
|
||||
.mapHomeCaptainController
|
||||
|
||||
Reference in New Issue
Block a user