This commit is contained in:
Hamza Aleghwairyeen
2024-03-31 02:24:27 +03:00
parent 66cd964a89
commit 874be94864
8 changed files with 71 additions and 53 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:math' as math;
import 'dart:math' show cos;
import 'package:SEFER/constant/table_names.dart';
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
@@ -501,7 +502,7 @@ update ui for totla results
isRideStarted = false;
isPriceWindow = false;
if (cartype == 'Comfort') {
totalCost = (price * rideTimerFromBegin).toString();
totalCost = price.toStringAsFixed(2);
}
box.write(BoxName.statusDriverLocation, 'off');
// changeRideToBeginToPassenger();
@@ -599,10 +600,24 @@ update ui for totla results
await Future.delayed(const Duration(seconds: 1));
recentDistanceToDash = Get.find<LocationController>().totalDistance;
rideTimerFromBegin = i;
price = rideTimerFromBegin ~/ 60 +
(recentDistanceToDash * 4); //todo from kazan
price = (price * .10) + price;
speed = Get.find<LocationController>().speed;
price = cartype == 'Comfort'
? (i ~/ 60) +
(recentDistanceToDash *
Get.find<HomeCaptainController>().comfortPrice)
: cartype == 'Speed'
? (i ~/ 60) +
(recentDistanceToDash *
Get.find<HomeCaptainController>().speedPrice)
: cartype == 'Delivery'
? (i ~/ 60) +
(recentDistanceToDash *
Get.find<HomeCaptainController>().deliveryPrice)
: (i ~/ 60) +
(recentDistanceToDash *
Get.find<HomeCaptainController>()
.freePrice); // $1 for each minute + $4 for each km
price = (price * .10) + price; // Add 10% tax
speed = Get.find<LocationController>().speed * 3.6;
progressTimerRideBegin = i / durationOfRide;
remainingTimeTimerRideBegin = durationOfRide - i;
remainingTimeTimerRideBegin < 60 ? driverEndPage = 160 : 100;
@@ -619,41 +634,6 @@ update ui for totla results
}
}
double calculateDistanceBetweenLocations(LatLng start, LatLng end) {
double startLat = start.latitude * math.pi / 180;
double startLon = start.longitude * math.pi / 180;
double endLat = end.latitude * math.pi / 180;
double endLon = end.longitude * math.pi / 180;
double dLat = endLat - startLat;
double dLon = endLon - startLon;
double a = math.pow(math.sin(dLat / 2), 2) +
math.cos(startLat) * math.cos(endLat) * math.pow(math.sin(dLon / 2), 2);
double c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a));
double distance = 6371000 * c; // Distance in meters
return distance;
}
double calculateAngleBetweenLocations(LatLng start, LatLng end) {
double startLat = start.latitude * math.pi / 180;
double startLon = start.longitude * math.pi / 180;
double endLat = end.latitude * math.pi / 180;
double endLon = end.longitude * math.pi / 180;
double dLon = endLon - startLon;
double y = math.sin(dLon) * cos(endLat);
double x = cos(startLat) * math.sin(endLat) -
math.sin(startLat) * cos(endLat) * cos(dLon);
double angle = math.atan2(y, x);
double angleDegrees = angle * 180 / math.pi;
return angleDegrees;
}
double recentDistanceToDash = 0;
double recentAngelToMarker = 0;
double speed = 0;
@@ -681,8 +661,8 @@ LIMIT
var lng = double.parse(previousLocationOfDrivers[0]['lng']);
LatLng prev = LatLng(lat, lng);
recentDistanceToDash =
calculateDistanceBetweenLocations(prev, myLocation);
// recentDistanceToDash =
// calculateDistanceBetweenLocations(prev, myLocation);
print('recentAngelToMarker $recentAngelToMarker');
print('recentDistanceToDash $recentDistanceToDash');
}