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;
|
||||
|
||||
late GeoidGrid geoidGrid;
|
||||
StreamSubscription<LocationData>? _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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user