Update: 2026-07-04 16:16:49
This commit is contained in:
@@ -11,6 +11,7 @@ import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:siro_driver/constant/box_name.dart';
|
||||
import 'package:siro_driver/constant/links.dart';
|
||||
import 'package:siro_driver/controller/car_platform_bridge.dart';
|
||||
import 'package:siro_driver/controller/functions/crud.dart';
|
||||
import 'package:siro_driver/controller/functions/tts.dart';
|
||||
import 'package:siro_driver/controller/home/navigation/decode_polyline_isolate.dart';
|
||||
@@ -90,6 +91,7 @@ class NavigationController extends GetxController
|
||||
String nextInstruction = "";
|
||||
int currentStepIndex = 0;
|
||||
String distanceToNextStep = "";
|
||||
double _distanceToNextStepMeters = 0.0;
|
||||
String totalDistanceRemaining = "";
|
||||
String estimatedTimeRemaining = "";
|
||||
dynamic currentManeuverModifier = 0;
|
||||
@@ -300,6 +302,7 @@ class NavigationController extends GetxController
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
CarPlatformBridge.ensureInitialized();
|
||||
_animController = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 1000));
|
||||
_animController!.addListener(() {
|
||||
@@ -546,6 +549,9 @@ class NavigationController extends GetxController
|
||||
_recomputeETA();
|
||||
_checkOffRoute(newLoc);
|
||||
}
|
||||
|
||||
_pushCarBridgeUpdate();
|
||||
|
||||
update();
|
||||
} catch (e) {
|
||||
Log.print("DEBUG: Error in _handleLocationUpdate: $e");
|
||||
@@ -1133,6 +1139,8 @@ class NavigationController extends GetxController
|
||||
bearing: _smoothedHeading, zoom: _targetZoom, tilt: _targetTilt);
|
||||
}
|
||||
|
||||
_pushCarBridgeUpdate();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -1153,6 +1161,7 @@ class NavigationController extends GetxController
|
||||
_finalDestination = null;
|
||||
isNavigating = false;
|
||||
routes = [];
|
||||
CarPlatformBridge.stopNavigation();
|
||||
await _flushBufferToServer();
|
||||
}
|
||||
routeSteps = [];
|
||||
@@ -1162,6 +1171,7 @@ class NavigationController extends GetxController
|
||||
nextInstruction = "";
|
||||
currentManeuverModifier = "siro";
|
||||
distanceToNextStep = "";
|
||||
_distanceToNextStepMeters = 0.0;
|
||||
totalDistanceRemaining = "";
|
||||
estimatedTimeRemaining = "";
|
||||
arrivalTime = "--:--";
|
||||
@@ -1197,6 +1207,7 @@ class NavigationController extends GetxController
|
||||
final distance = Geolocator.distanceBetween(
|
||||
pos.latitude, pos.longitude, endLatLng.latitude, endLatLng.longitude);
|
||||
|
||||
_distanceToNextStepMeters = distance;
|
||||
distanceToNextStep = distance > 1000
|
||||
? "${(distance / 1000).toStringAsFixed(1)} km"
|
||||
: "${distance.toStringAsFixed(0)} m";
|
||||
@@ -1224,6 +1235,13 @@ class NavigationController extends GetxController
|
||||
: "Then ${routeSteps[currentStepIndex + 1]['text']}")
|
||||
: (langCode == 'ar' ? "ستصل إلى وجهتك" : "Arriving soon");
|
||||
_nextInstructionSpoken = false;
|
||||
CarPlatformBridge.updateInstruction(
|
||||
instruction: currentInstruction,
|
||||
maneuver: currentManeuverModifier is int
|
||||
? currentManeuverModifier as int
|
||||
: int.tryParse(currentManeuverModifier.toString()) ?? 0,
|
||||
distanceToStep: 0.0,
|
||||
);
|
||||
update();
|
||||
} else {
|
||||
_finishNavigation();
|
||||
@@ -1241,6 +1259,7 @@ class NavigationController extends GetxController
|
||||
if (!isMuted) {
|
||||
Get.find<TextToSpeechController>().speakText(currentInstruction);
|
||||
}
|
||||
CarPlatformBridge.stopNavigation();
|
||||
_flushBufferToServer();
|
||||
update();
|
||||
}
|
||||
@@ -1303,6 +1322,34 @@ class NavigationController extends GetxController
|
||||
return R * 2 * atan2(sqrt(a), sqrt(1 - a));
|
||||
}
|
||||
|
||||
void _pushCarBridgeUpdate() {
|
||||
if (!isNavigating) return;
|
||||
final etaSeconds = _routeTotalDurationS > 0
|
||||
? (_fullRouteCoordinates.isNotEmpty
|
||||
? _routeTotalDurationS *
|
||||
(_fullRouteCoordinates.length - _lastTraveledIndexInFullRoute) /
|
||||
_fullRouteCoordinates.length
|
||||
: 0.0)
|
||||
: 0.0;
|
||||
CarPlatformBridge.updateNavState(
|
||||
lat: myLocation?.latitude ?? 0.0,
|
||||
lng: myLocation?.longitude ?? 0.0,
|
||||
bearing: _smoothedHeading,
|
||||
speed: currentSpeed,
|
||||
instruction: currentInstruction,
|
||||
distanceToStep: _distanceToNextStepMeters,
|
||||
totalDistance: _routeTotalDistanceM * (_fullRouteCoordinates.isNotEmpty
|
||||
? (_fullRouteCoordinates.length - _lastTraveledIndexInFullRoute) /
|
||||
_fullRouteCoordinates.length
|
||||
: 0.0),
|
||||
eta: etaSeconds,
|
||||
maneuver: currentManeuverModifier is int
|
||||
? currentManeuverModifier as int
|
||||
: int.tryParse(currentManeuverModifier.toString()) ?? 0,
|
||||
isNavigating: true,
|
||||
);
|
||||
}
|
||||
|
||||
double _kmToLatDelta(double km) => km / 111.32;
|
||||
double _kmToLngDelta(double km, double lat) =>
|
||||
km / (111.32 * cos(lat * pi / 180));
|
||||
|
||||
Reference in New Issue
Block a user