1/1/1
This commit is contained in:
@@ -21,12 +21,16 @@ import '../../functions/location_controller.dart';
|
||||
class MapDriverController extends GetxController {
|
||||
bool isLoading = true;
|
||||
List data = [];
|
||||
List dataDestination = [];
|
||||
LatLngBounds? boundsData;
|
||||
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
|
||||
final List<LatLng> polylineCoordinates = [];
|
||||
final List<LatLng> polylineCoordinatesDestination = [];
|
||||
List<Polyline> polyLines = [];
|
||||
List<Polyline> polyLinesDestination = [];
|
||||
Set<Marker> markers = {};
|
||||
late String passengerLocation;
|
||||
late String passengerDestination;
|
||||
late String duration;
|
||||
late String distance;
|
||||
late String name;
|
||||
@@ -46,7 +50,7 @@ class MapDriverController extends GetxController {
|
||||
bool isBtnRideBegin = false;
|
||||
bool isRideFinished = false;
|
||||
bool isRideStarted = false;
|
||||
double passengerInfoWindow = Get.height * .32;
|
||||
double passengerInfoWindow = Get.height * .35;
|
||||
double progress = 0;
|
||||
double progressToPassenger = 0;
|
||||
bool isRideBegin = false;
|
||||
@@ -69,12 +73,12 @@ class MapDriverController extends GetxController {
|
||||
mapController = controller;
|
||||
controller.getVisibleRegion();
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLngZoom(myLocation, 15),
|
||||
CameraUpdate.newLatLngZoom(myLocation, 17),
|
||||
);
|
||||
update();
|
||||
|
||||
// Set up a timer or interval to trigger the marker update every 3 seconds.
|
||||
timer = Timer.periodic(const Duration(seconds: 3), (_) {
|
||||
timer = Timer.periodic(const Duration(seconds: 2), (_) {
|
||||
updateMarker();
|
||||
});
|
||||
}
|
||||
@@ -111,7 +115,9 @@ class MapDriverController extends GetxController {
|
||||
|
||||
void clearPolyline() {
|
||||
polyLines = [];
|
||||
polyLinesDestination = [];
|
||||
polylineCoordinates.clear();
|
||||
polylineCoordinatesDestination.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -371,6 +377,45 @@ class MapDriverController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
getMapDestination(String origin, destination) async {
|
||||
var url =
|
||||
('${AppLink.googleMapsLink}directions/json?&language=en&avoid=tolls|ferries&destination=$destination&origin=$origin&key=${AK.mapAPIKEY}');
|
||||
|
||||
var response = await CRUD().getGoogleApi(link: url, payload: {});
|
||||
dataDestination = response['routes'][0]['legs'];
|
||||
// print(data);
|
||||
final points =
|
||||
decodePolyline(response["routes"][0]["overview_polyline"]["points"]);
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
double lat = points[i][0].toDouble();
|
||||
double lng = points[i][1].toDouble();
|
||||
polylineCoordinatesDestination.add(LatLng(lat, lng));
|
||||
}
|
||||
if (polyLinesDestination.isNotEmpty) {
|
||||
clearPolyline();
|
||||
var polyline = Polyline(
|
||||
polylineId: PolylineId(response["routes"][0]["summary"]),
|
||||
points: polylineCoordinatesDestination,
|
||||
width: 10,
|
||||
color: AppColor.redColor,
|
||||
);
|
||||
polyLinesDestination.add(polyline);
|
||||
// rideConfirm = false;
|
||||
update();
|
||||
} else {
|
||||
var polyline = Polyline(
|
||||
polylineId: PolylineId(response["routes"][0]["summary"]),
|
||||
points: polylineCoordinatesDestination,
|
||||
width: 10,
|
||||
color: AppColor.redColor,
|
||||
);
|
||||
|
||||
polyLinesDestination.add(polyline);
|
||||
// rideConfirm = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void changePassengerInfoWindow() {
|
||||
isPassengerInfoWindow = !isPassengerInfoWindow;
|
||||
passengerInfoWindow = isPassengerInfoWindow == true ? 200 : 0;
|
||||
@@ -382,6 +427,7 @@ class MapDriverController extends GetxController {
|
||||
mapAPIKEY = await storage.read(key: BoxName.mapAPIKEY);
|
||||
// Get the passenger location from the arguments.
|
||||
passengerLocation = Get.arguments['passengerLocation'];
|
||||
passengerDestination = Get.arguments['passengerDestination'];
|
||||
duration = Get.arguments['Duration'];
|
||||
passengerId = Get.arguments['passengerId'];
|
||||
driverId = Get.arguments['driverId'];
|
||||
@@ -401,6 +447,7 @@ class MapDriverController extends GetxController {
|
||||
String origin = '$lat,$lng';
|
||||
// Set the origin and destination coordinates for the Google Maps directions request.
|
||||
getMap(origin, passengerLocation);
|
||||
await getMapDestination(passengerLocation, passengerDestination);
|
||||
addCustomCarIcon();
|
||||
// updateMarker();
|
||||
startTimerToShowPassengerInfoWindowFromDriver();
|
||||
|
||||
Reference in New Issue
Block a user