From 48413ba344ef66f4da4e8cbd82c1d914b9c03109 Mon Sep 17 00:00:00 2001 From: "torok.istvan" Date: Sat, 9 May 2026 23:01:00 +0200 Subject: [PATCH] =?UTF-8?q?MapController:=20ha=20nincs=20k=C3=BCls=C5=91?= =?UTF-8?q?=20GPS=20csatlakoztatva,=20akkor=20a=20bels=C5=91t=20haszn?= =?UTF-8?q?=C3=A1lja?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/map_controller.dart | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/pages/map/presentation/controllers/map_controller.dart b/lib/pages/map/presentation/controllers/map_controller.dart index 190d27b..8885a68 100644 --- a/lib/pages/map/presentation/controllers/map_controller.dart +++ b/lib/pages/map/presentation/controllers/map_controller.dart @@ -103,6 +103,7 @@ class MapViewController extends GetxController { RxDouble distance = 0.0.obs; late GeoidGrid geoidGrid; + StreamSubscription? _phoneLocationSub; TextEditingController pointIdController = TextEditingController(); TextEditingController pointDescriptionController = TextEditingController(); @@ -193,6 +194,9 @@ class MapViewController extends GetxController { // connection = null; print("BluetoothTestController dispose ...."); } + + _stopPhoneGps(); + pointDescriptionController.dispose(); pointIdController.dispose(); gpsHeightController.dispose(); @@ -319,6 +323,39 @@ class MapViewController extends GetxController { mapController.move(LatLng(currentLatitude.value, currentLongitude.value), currentZoom.value); _updateCurrentLocationMarker(); + + if (!gpsIsConnected.value) { + _startPhoneGps(); + } + } + + void _startPhoneGps() async { + // Ha már fut, nem indítjuk újra + if (_phoneLocationSub != null) return; + + final location = Location(); + + // Engedélyek — már megvan a _getInitialLocation()-ból, + // de biztonságos újra ellenőrizni + final permission = await location.hasPermission(); + if (permission == PermissionStatus.denied) return; + + // Folyamatos frissítés indítása + _phoneLocationSub = location.onLocationChanged.listen((LocationData data) { + if (gpsIsConnected.value) { + // Ha közben csatlakozott a külső GPS — leállítjuk magunkat + _stopPhoneGps(); + return; + } + currentLatitude.value = data.latitude ?? currentLatitude.value; + currentLongitude.value = data.longitude ?? currentLongitude.value; + _updateCurrentLocationMarker(); + }); + } + + void _stopPhoneGps() { + _phoneLocationSub?.cancel(); + _phoneLocationSub = null; } void connectToGps() { @@ -327,6 +364,7 @@ class MapViewController extends GetxController { connection = value; gpsIsConnected.value = true; print("GPS is connected ..."); + _stopPhoneGps(); connection.input!.listen(_onDataReceived); }); @@ -337,6 +375,7 @@ class MapViewController extends GetxController { if (gpsIsConnected.value) { connection.close(); gpsIsConnected.value = false; + _startPhoneGps(); print("GPS is disconnected ...."); } if (ntripIsConnected.value) {