Track, nyomkövetés hozzáadása
This commit is contained in:
@@ -104,6 +104,7 @@ class MapViewController extends GetxController {
|
||||
|
||||
late GeoidGrid geoidGrid;
|
||||
StreamSubscription<LocationData>? _phoneLocationSub;
|
||||
final _phoneLocation = Location();
|
||||
|
||||
TextEditingController pointIdController = TextEditingController();
|
||||
TextEditingController pointDescriptionController = TextEditingController();
|
||||
@@ -325,30 +326,48 @@ class MapViewController extends GetxController {
|
||||
_updateCurrentLocationMarker();
|
||||
|
||||
if (!gpsIsConnected.value) {
|
||||
_startPhoneGps();
|
||||
await _startPhoneGps();
|
||||
}
|
||||
}
|
||||
|
||||
void _startPhoneGps() async {
|
||||
// Ha már fut, nem indítjuk újra
|
||||
Future<void> _startPhoneGps() async {
|
||||
if (_phoneLocationSub != null) return;
|
||||
|
||||
final location = Location();
|
||||
// Frissítési beállítások — ezt a location csomag megköveteli
|
||||
await _phoneLocation.changeSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
interval: 1000, // ms — másodpercenkénti frissítés
|
||||
distanceFilter: 0, // méter — minden frissítés jöjjön
|
||||
);
|
||||
|
||||
// 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;
|
||||
// Engedély teljes körű ellenőrzése
|
||||
var permission = await _phoneLocation.hasPermission();
|
||||
if (permission == PermissionStatus.denied) {
|
||||
permission = await _phoneLocation.requestPermission();
|
||||
}
|
||||
if (permission != PermissionStatus.granted &&
|
||||
permission != PermissionStatus.grantedLimited) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Folyamatos frissítés indítása
|
||||
_phoneLocationSub = location.onLocationChanged.listen((LocationData data) {
|
||||
// GPS szolgáltatás ellenőrzése
|
||||
bool serviceEnabled = await _phoneLocation.serviceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
serviceEnabled = await _phoneLocation.requestService();
|
||||
if (!serviceEnabled) return;
|
||||
}
|
||||
|
||||
print('Phone GPS: stream starting...');
|
||||
|
||||
_phoneLocationSub = _phoneLocation.onLocationChanged.listen((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;
|
||||
if (data.latitude == null || data.longitude == null) return;
|
||||
|
||||
currentLatitude.value = data.latitude!;
|
||||
currentLongitude.value = data.longitude!;
|
||||
_updateCurrentLocationMarker();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user