2/6/1
This commit is contained in:
@@ -212,6 +212,7 @@ class MapPassengerController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
List<String> coordinatesWithoutEmpty = [];
|
||||
void getMapPointsForAllMethods() async {
|
||||
print(placesCoordinate.toString());
|
||||
clearPolyline();
|
||||
@@ -221,16 +222,24 @@ class MapPassengerController extends GetxController {
|
||||
distanceOfDestnation = 0;
|
||||
wayPointSheetHeight = 0;
|
||||
haveSteps = true;
|
||||
for (var i = 0; i < Get.find<WayPointController>().wayPoints.length; i++) {
|
||||
if (placesCoordinate[i + 1].toString() != '') {
|
||||
|
||||
// Filter out empty value
|
||||
coordinatesWithoutEmpty =
|
||||
placesCoordinate.where((coord) => coord.isNotEmpty).toList();
|
||||
latestPosition = LatLng(
|
||||
double.parse(coordinatesWithoutEmpty.last.split(',')[0]),
|
||||
double.parse(coordinatesWithoutEmpty.last.split(',')[1]));
|
||||
// print(coordinatesWithoutEmpty);
|
||||
for (var i = 0; i < coordinatesWithoutEmpty.length; i++) {
|
||||
if ((i + 1) < coordinatesWithoutEmpty.length) {
|
||||
await getMapPoints(
|
||||
placesCoordinate[i].toString(),
|
||||
placesCoordinate[i + 1].toString(),
|
||||
coordinatesWithoutEmpty[i].toString(),
|
||||
coordinatesWithoutEmpty[i + 1].toString(),
|
||||
i,
|
||||
);
|
||||
}
|
||||
}
|
||||
updateCameraForDistanceAfterGetMap();
|
||||
|
||||
// isWayPointStopsSheet = false;
|
||||
if (haveSteps) {
|
||||
String latestWaypoint =
|
||||
@@ -240,9 +249,11 @@ class MapPassengerController extends GetxController {
|
||||
double.parse(latestWaypoint.split(',')[1]),
|
||||
);
|
||||
}
|
||||
updateCameraForDistanceAfterGetMap();
|
||||
changeWayPointStopsSheet();
|
||||
bottomSheet();
|
||||
showBottomSheet1();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -1207,11 +1218,7 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
void addCustomCarIcon() {
|
||||
ImageConfiguration config = ImageConfiguration(
|
||||
// size: Size(Get.width * .6, Get.height * .6),
|
||||
size: const Size(30, 30),
|
||||
devicePixelRatio: Get.pixelRatio
|
||||
// scale: 1.0,
|
||||
);
|
||||
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
|
||||
BitmapDescriptor.fromAssetImage(config, 'assets/images/car.png',
|
||||
mipmaps: false)
|
||||
.then((value) {
|
||||
@@ -1220,6 +1227,17 @@ class MapPassengerController extends GetxController {
|
||||
});
|
||||
}
|
||||
|
||||
void addCustomStepIcon() {
|
||||
ImageConfiguration config = ImageConfiguration(
|
||||
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
|
||||
BitmapDescriptor.fromAssetImage(config, 'assets/images/brand.png',
|
||||
mipmaps: false)
|
||||
.then((value) {
|
||||
tripIcon = value;
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getLocation() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
@@ -1512,7 +1530,64 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
double distanceOfDestnation = 0;
|
||||
bool haveSteps = false;
|
||||
late LatLng latestPosition = LatLng(0, 0);
|
||||
late LatLng latestPosition;
|
||||
// getMapPoints(String originSteps, String destinationSteps, int index) async {
|
||||
// isWayPointStopsSheetUtilGetMap = false;
|
||||
// haveSteps = true;
|
||||
// await getCarsLocationByPassenger();
|
||||
// // isLoading = true;
|
||||
// update();
|
||||
// String url = '${AppLink.googleMapsLink}directions/json'
|
||||
// '?origin=${coordinatesWithoutEmpty.first}'
|
||||
// '&destination=${coordinatesWithoutEmpty.last}';
|
||||
// if (coordinatesWithoutEmpty.length > 2) {
|
||||
// String waypoints = "";
|
||||
// for (int i = 1; i < coordinatesWithoutEmpty.length - 1; i++) {
|
||||
// waypoints += "${coordinatesWithoutEmpty[i]}|";
|
||||
// }
|
||||
// waypoints = waypoints.substring(0, waypoints.length - 1);
|
||||
// url += "&waypoints=$waypoints";
|
||||
// }
|
||||
// url += '&language=en'
|
||||
// '&avoid=tolls|ferries'
|
||||
// '&key=${AK.mapAPIKEY}';
|
||||
// var response = await CRUD().getGoogleApi(link: url, payload: {});
|
||||
// data = response['routes'][0]['legs'];
|
||||
// // //print(data);
|
||||
// // isLoading = false;
|
||||
// int durationToRide0 = data[0]['duration']['value'];
|
||||
// durationToRide = durationToRide + durationToRide0;
|
||||
// print(durationToRide0);
|
||||
// print('durationToRide = $durationToRide');
|
||||
// distance = distanceOfDestnation + (data[0]['distance']['value']) / 1000;
|
||||
// update();
|
||||
// final points =
|
||||
// decodePolyline(response["routes"][0]["overview_polyline"]["points"]);
|
||||
// for (int i = 0; i < points.length; i++) {
|
||||
// if (points[i][0].toString() != '') {
|
||||
// double lat = points[i][0].toDouble();
|
||||
// double lng = points[i][1].toDouble();
|
||||
// polylineCoordinatesPointsAll[index].add(LatLng(lat, lng));
|
||||
// }
|
||||
// }
|
||||
// // Define the northeast and southwest coordinates
|
||||
// update();
|
||||
// if (polyLines.isNotEmpty) {
|
||||
// // clearPolyline();
|
||||
// } else {
|
||||
// var polyline = Polyline(
|
||||
// polylineId: PolylineId(response["routes"][0]["summary"]),
|
||||
// points: polylineCoordinatesPointsAll[index],
|
||||
// width: 10,
|
||||
// color: Colors.blue,
|
||||
// );
|
||||
// polyLines.add(polyline);
|
||||
// rideConfirm = false;
|
||||
// // isMarkersShown = true;
|
||||
// update();
|
||||
// }
|
||||
// }
|
||||
|
||||
getMapPoints(String originSteps, String destinationSteps, int index) async {
|
||||
isWayPointStopsSheetUtilGetMap = false;
|
||||
// haveSteps = true;
|
||||
@@ -1529,7 +1604,10 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
int durationToRide0 = data[0]['duration']['value'];
|
||||
durationToRide = durationToRide + durationToRide0;
|
||||
print(durationToRide0);
|
||||
print('durationToRide = $durationToRide');
|
||||
distance = distanceOfDestnation + (data[0]['distance']['value']) / 1000;
|
||||
|
||||
update();
|
||||
final points =
|
||||
decodePolyline(response["routes"][0]["overview_polyline"]["points"]);
|
||||
@@ -1560,22 +1638,35 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
|
||||
void updateCameraForDistanceAfterGetMap() {
|
||||
// Get the non-empty values from the data list
|
||||
List<LatLng> nonEmptyValues = data
|
||||
.where((element) => element != null && element.isNotEmpty)
|
||||
.map((element) => LatLng(element['lat'], element['lng']))
|
||||
.toList();
|
||||
LatLng coord1 = LatLng(
|
||||
double.parse(coordinatesWithoutEmpty.first.split(',')[0]),
|
||||
double.parse(coordinatesWithoutEmpty.first.split(',')[1]));
|
||||
|
||||
// Define the northeast and southwest coordinates
|
||||
LatLng northeast = nonEmptyValues.first;
|
||||
LatLng southwest = nonEmptyValues.last;
|
||||
LatLng coord2 = LatLng(
|
||||
double.parse(coordinatesWithoutEmpty.last.split(',')[0]),
|
||||
double.parse(coordinatesWithoutEmpty.last.split(',')[1]));
|
||||
|
||||
LatLng northeast;
|
||||
LatLng southwest;
|
||||
|
||||
if (coord1.latitude > coord2.latitude) {
|
||||
northeast = coord1;
|
||||
southwest = coord2;
|
||||
} else {
|
||||
northeast = coord2;
|
||||
southwest = coord1;
|
||||
}
|
||||
|
||||
// Create the LatLngBounds object
|
||||
LatLngBounds bounds =
|
||||
LatLngBounds(northeast: northeast, southwest: southwest);
|
||||
|
||||
print('boundsbounds');
|
||||
print(bounds);
|
||||
print('boundsbounds');
|
||||
|
||||
// Fit the camera to the bounds
|
||||
var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 130);
|
||||
var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 160);
|
||||
mapController!.animateCamera(cameraUpdate);
|
||||
update();
|
||||
}
|
||||
@@ -1614,6 +1705,8 @@ class MapPassengerController extends GetxController {
|
||||
var firstElement = decode["message"][0];
|
||||
totalPassenger = totalPassenger -
|
||||
(totalPassenger * int.parse(firstElement['amount']) / 100);
|
||||
totalDriver = totalDriver -
|
||||
(totalDriver * int.parse(firstElement['amount']) / 100);
|
||||
promoTaken = true;
|
||||
update();
|
||||
//print(totalPassenger);
|
||||
@@ -1635,13 +1728,15 @@ class MapPassengerController extends GetxController {
|
||||
Future bottomSheet() async {
|
||||
if (data.isNotEmpty) {
|
||||
durationToAdd = Duration(seconds: durationToRide);
|
||||
//print('durationToRide----- $durationToRide');
|
||||
print('durationToRide----- $durationToRide');
|
||||
print('durationToAdd----- $durationToAdd');
|
||||
hours = durationToAdd.inHours;
|
||||
minutes = (durationToAdd.inMinutes % 60).round();
|
||||
DateTime currentTime = DateTime.now();
|
||||
newTime = currentTime.add(durationToAdd);
|
||||
averageDuration = (durationToRide / 60) / distance;
|
||||
costDuration = (durationToRide / 60) * averageDuration * 0.016;
|
||||
print('costDuration----- $costDuration');
|
||||
var totalDriver1 = cost + costDuration;
|
||||
totalPassenger = totalDriver1 + (totalDriver1 * .16);
|
||||
totalDriver = totalDriver1 + (totalDriver1 * .16);
|
||||
@@ -1766,6 +1861,7 @@ class MapPassengerController extends GetxController {
|
||||
getNearestDriverByPassengerLocation();
|
||||
addCustomPicker();
|
||||
addCustomCarIcon();
|
||||
addCustomStepIcon();
|
||||
addCustomStartIcon();
|
||||
addCustomEndIcon();
|
||||
startMarkerReloading();
|
||||
|
||||
Reference in New Issue
Block a user