MapController: ha nincs külső GPS csatlakoztatva, akkor a belsőt használja
This commit is contained in:
parent
81f1fa5cd7
commit
48413ba344
@ -103,6 +103,7 @@ class MapViewController extends GetxController {
|
|||||||
RxDouble distance = 0.0.obs;
|
RxDouble distance = 0.0.obs;
|
||||||
|
|
||||||
late GeoidGrid geoidGrid;
|
late GeoidGrid geoidGrid;
|
||||||
|
StreamSubscription<LocationData>? _phoneLocationSub;
|
||||||
|
|
||||||
TextEditingController pointIdController = TextEditingController();
|
TextEditingController pointIdController = TextEditingController();
|
||||||
TextEditingController pointDescriptionController = TextEditingController();
|
TextEditingController pointDescriptionController = TextEditingController();
|
||||||
@ -193,6 +194,9 @@ class MapViewController extends GetxController {
|
|||||||
// connection = null;
|
// connection = null;
|
||||||
print("BluetoothTestController dispose ....");
|
print("BluetoothTestController dispose ....");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_stopPhoneGps();
|
||||||
|
|
||||||
pointDescriptionController.dispose();
|
pointDescriptionController.dispose();
|
||||||
pointIdController.dispose();
|
pointIdController.dispose();
|
||||||
gpsHeightController.dispose();
|
gpsHeightController.dispose();
|
||||||
@ -319,6 +323,39 @@ class MapViewController extends GetxController {
|
|||||||
mapController.move(LatLng(currentLatitude.value, currentLongitude.value),
|
mapController.move(LatLng(currentLatitude.value, currentLongitude.value),
|
||||||
currentZoom.value);
|
currentZoom.value);
|
||||||
_updateCurrentLocationMarker();
|
_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() {
|
void connectToGps() {
|
||||||
@ -327,6 +364,7 @@ class MapViewController extends GetxController {
|
|||||||
connection = value;
|
connection = value;
|
||||||
gpsIsConnected.value = true;
|
gpsIsConnected.value = true;
|
||||||
print("GPS is connected ...");
|
print("GPS is connected ...");
|
||||||
|
_stopPhoneGps();
|
||||||
|
|
||||||
connection.input!.listen(_onDataReceived);
|
connection.input!.listen(_onDataReceived);
|
||||||
});
|
});
|
||||||
@ -337,6 +375,7 @@ class MapViewController extends GetxController {
|
|||||||
if (gpsIsConnected.value) {
|
if (gpsIsConnected.value) {
|
||||||
connection.close();
|
connection.close();
|
||||||
gpsIsConnected.value = false;
|
gpsIsConnected.value = false;
|
||||||
|
_startPhoneGps();
|
||||||
print("GPS is disconnected ....");
|
print("GPS is disconnected ....");
|
||||||
}
|
}
|
||||||
if (ntripIsConnected.value) {
|
if (ntripIsConnected.value) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user