fixed popup buttons added location stream and center button
This commit is contained in:
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:rogapp/widgets/debug_widget.dart';
|
||||
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
|
||||
|
||||
class LocationController extends GetxController {
|
||||
// Reactive variable to hold the current position
|
||||
@ -10,8 +11,15 @@ class LocationController extends GetxController {
|
||||
|
||||
// Subscription to the position stream
|
||||
StreamSubscription<Position>? positionStream;
|
||||
|
||||
final locationMarkerPositionStreamController =
|
||||
StreamController<LocationMarkerPosition?>.broadcast();
|
||||
|
||||
bool isStreamPaused = false;
|
||||
|
||||
Stream<LocationMarkerPosition?> get locationMarkerPositionStream =>
|
||||
locationMarkerPositionStreamController.stream;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@ -99,36 +107,33 @@ class LocationController extends GetxController {
|
||||
|
||||
// Set up the location options
|
||||
const locationOptions =
|
||||
LocationSettings(accuracy: LocationAccuracy.high, distanceFilter: 10);
|
||||
LocationSettings(accuracy: LocationAccuracy.high, distanceFilter: 0);
|
||||
|
||||
// Start listening to the position stream
|
||||
// positionStream =
|
||||
// Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
||||
// (Position position) {
|
||||
// currentPosition.value = position;
|
||||
// }, onError: (e) {
|
||||
// // Handle errors or exceptions in the stream
|
||||
// // You might want to log this error or use a state to show error messages
|
||||
// });
|
||||
await positionStream?.cancel();
|
||||
|
||||
StreamSubscription<Position> positionStream =
|
||||
Geolocator.getPositionStream(locationSettings: locationOptions)
|
||||
.listen((Position? position) {
|
||||
// print(position == null
|
||||
// ? 'Unknown'
|
||||
// : '${position.latitude.toString()}, ${position.longitude.toString()}');
|
||||
if (position?.accuracy != null && position!.accuracy <= 15) {
|
||||
currentPosition.value = position;
|
||||
}
|
||||
|
||||
// LogManager().addLog(
|
||||
// "GPS : ${position!.latitude.toString()}, ${position.longitude.toString()} - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
|
||||
});
|
||||
positionStream =
|
||||
Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
||||
(Position? position) {
|
||||
if (position != null) {
|
||||
final LocationMarkerPosition locationMarkerPosition =
|
||||
LocationMarkerPosition(
|
||||
latitude: position.latitude,
|
||||
longitude: position.longitude,
|
||||
accuracy: position.accuracy);
|
||||
locationMarkerPositionStreamController.add(locationMarkerPosition);
|
||||
} else {
|
||||
locationMarkerPositionStreamController.add(null);
|
||||
}
|
||||
},
|
||||
onError: (e) {
|
||||
locationMarkerPositionStreamController.addError(e);
|
||||
},
|
||||
);
|
||||
|
||||
// Resume stream if it was paused previously
|
||||
if (isStreamPaused) {
|
||||
isStreamPaused = false;
|
||||
positionStream.resume();
|
||||
positionStream!.resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user