12/18/1
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:sefer_driver/constant/style.dart';
|
||||
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/links.dart';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:SEFER/controller/firebase/firbase_messge.dart';
|
||||
import 'package:sefer_driver/controller/firebase/firbase_messge.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/links.dart';
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/controller/functions/location_controller.dart';
|
||||
import 'package:sefer_driver/constant/box_name.dart';
|
||||
import 'package:sefer_driver/controller/functions/location_controller.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
import '../../constant/links.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/widgets/mydialoug.dart';
|
||||
import '../functions/crud.dart';
|
||||
|
||||
@@ -16,22 +18,6 @@ class RideAvailableController extends GetxController {
|
||||
Map rideAvailableMap = {};
|
||||
late LatLng southwest;
|
||||
late LatLng northeast;
|
||||
// LatLngBounds calculateBounds(
|
||||
// double centerLat, double centerLng, double radius) {
|
||||
// // double radius = 4000; // 10 km in meters
|
||||
|
||||
// southwest = LatLng(
|
||||
// centerLat - (radius / 111000),
|
||||
// centerLng - (radius / (111000 * cos(centerLat))),
|
||||
// );
|
||||
|
||||
// northeast = LatLng(
|
||||
// centerLat + (radius / 111000),
|
||||
// centerLng + (radius / (111000 * cos(centerLat))),
|
||||
// );
|
||||
|
||||
// return LatLngBounds(southwest: southwest, northeast: northeast);
|
||||
// }
|
||||
|
||||
LatLngBounds calculateBounds(double lat, double lng, double radiusInMeters) {
|
||||
const double earthRadius = 6378137.0; // Earth's radius in meters
|
||||
@@ -67,22 +53,48 @@ class RideAvailableController extends GetxController {
|
||||
);
|
||||
}
|
||||
|
||||
double calculateDistance(String startLocation) {
|
||||
List<String> startLocationParts = startLocation.split(',');
|
||||
double startLatitude = double.parse(startLocationParts[0]);
|
||||
double startLongitude = double.parse(startLocationParts[1]);
|
||||
|
||||
// Assuming currentLocation is the driver's location
|
||||
double currentLatitude = Get.find<LocationController>().latitude;
|
||||
double currentLongitude = Get.find<LocationController>().longitude;
|
||||
|
||||
return Geolocator.distanceBetween(
|
||||
currentLatitude,
|
||||
currentLongitude,
|
||||
startLatitude,
|
||||
startLongitude,
|
||||
);
|
||||
}
|
||||
|
||||
// void sortRidesByDistance() {
|
||||
// rideAvailableMap['message'].sort((a, b) {
|
||||
// double distanceA = calculateDistance(a['start_location']);
|
||||
// double distanceB = calculateDistance(b['start_location']);
|
||||
// return distanceA.compareTo(distanceB);
|
||||
// });
|
||||
// }
|
||||
|
||||
getRideAvailable() async {
|
||||
isLoading = true;
|
||||
LatLngBounds bounds = calculateBounds(
|
||||
Get.find<LocationController>().myLocation.latitude,
|
||||
Get.find<LocationController>().myLocation.longitude,
|
||||
4000);
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getRideWaiting,
|
||||
payload: {
|
||||
"carType": box.read(BoxName.carTypeOfDriver).toString(),
|
||||
'southwestLat': bounds.southwest.latitude.toString(),
|
||||
'southwestLon': bounds.southwest.longitude.toString(),
|
||||
'northeastLat': bounds.northeast.latitude.toString(),
|
||||
'northeastLon': bounds.northeast.longitude.toString(),
|
||||
},
|
||||
);
|
||||
var payload = {
|
||||
// "carType": box.read(BoxName.carTypeOfDriver).toString(),
|
||||
'southwestLat': bounds.southwest.latitude.toString(),
|
||||
'southwestLon': bounds.southwest.longitude.toString(),
|
||||
'northeastLat': bounds.northeast.latitude.toString(),
|
||||
'northeastLon': bounds.northeast.longitude.toString(),
|
||||
};
|
||||
Log.print('payload: ${payload}');
|
||||
var res = await CRUD().get(link: AppLink.getRideWaiting, payload: payload);
|
||||
Log.print('res: ${res}');
|
||||
|
||||
if (res != 'failure') {
|
||||
rideAvailableMap = jsonDecode(res);
|
||||
isLoading = false;
|
||||
@@ -92,16 +104,6 @@ class RideAvailableController extends GetxController {
|
||||
Get.back();
|
||||
Get.back();
|
||||
});
|
||||
// Get.defaultDialog(
|
||||
// title: "No Rides Available".tr,
|
||||
// middleText: '',
|
||||
// titleStyle: AppStyle.title,
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'Ok'.tr,
|
||||
// onPressed: () {
|
||||
// Get.back();
|
||||
// Get.back();
|
||||
// }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user