fixed GPS issue
This commit is contained in:
@ -3,6 +3,7 @@ import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_binding.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/routes/app_pages.dart';
|
||||
import 'package:rogapp/utils/string_values.dart';
|
||||
// import 'package:is_lock_screen/is_lock_screen.dart';
|
||||
@ -58,7 +59,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
case AppLifecycleState.resumed:
|
||||
print("RESUMED");
|
||||
DestinationController destinationController = Get.find<DestinationController>();
|
||||
destinationController.initGPS();
|
||||
if(destinationController.positionStream == null){
|
||||
destinationController.startGPSTimer();
|
||||
}
|
||||
break;
|
||||
case AppLifecycleState.inactive:
|
||||
print("INACTIVE");
|
||||
|
||||
@ -52,6 +52,10 @@ class DestinationController extends GetxController {
|
||||
List<String> gps = <String>["-- stating --"].obs;
|
||||
List<String> locationPermission = <String>[" -- starting -- "].obs;
|
||||
|
||||
StreamSubscription<Position>? positionStream;
|
||||
|
||||
Timer? _GPStimer;
|
||||
|
||||
var travelMode = 0.obs;
|
||||
|
||||
bool skip_gps = false;
|
||||
@ -324,7 +328,8 @@ class DestinationController extends GetxController {
|
||||
|
||||
db.deleteAllDestinations().then((value) {
|
||||
PopulateDestinations();
|
||||
initGPS();
|
||||
startGPSTimer();
|
||||
//initGPS();
|
||||
});
|
||||
|
||||
// currentSelectedDestinations.forEach((element) {
|
||||
@ -517,10 +522,10 @@ class DestinationController extends GetxController {
|
||||
|
||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||
locationSettings = AndroidSettings(
|
||||
accuracy: LocationAccuracy.bestForNavigation,
|
||||
distanceFilter: 0,
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter: 1,
|
||||
forceLocationManager: true,
|
||||
intervalDuration: const Duration(seconds: 1),
|
||||
intervalDuration: const Duration(seconds: 3),
|
||||
//(Optional) Set foreground notification config to keep the app alive
|
||||
//when going to the background
|
||||
foregroundNotificationConfig: const ForegroundNotificationConfig(
|
||||
@ -532,7 +537,7 @@ class DestinationController extends GetxController {
|
||||
} else if (defaultTargetPlatform == TargetPlatform.iOS ||
|
||||
defaultTargetPlatform == TargetPlatform.macOS) {
|
||||
locationSettings = AppleSettings(
|
||||
accuracy: LocationAccuracy.bestForNavigation,
|
||||
accuracy: LocationAccuracy.high,
|
||||
activityType: ActivityType.fitness,
|
||||
distanceFilter: 0,
|
||||
pauseLocationUpdatesAutomatically: false,
|
||||
@ -546,8 +551,7 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
|
||||
try {
|
||||
StreamSubscription<Position> positionStream =
|
||||
Geolocator.getPositionStream(locationSettings: locationSettings)
|
||||
positionStream = Geolocator.getPositionStream(locationSettings: locationSettings)
|
||||
.listen((Position? position) {
|
||||
current_lat = position != null ? position.latitude : 0;
|
||||
current_lon = position != null ? position.longitude : 0;
|
||||
@ -565,9 +569,9 @@ class DestinationController extends GetxController {
|
||||
//String user_id = indexController.currentUser[0]["user"]["id"].toString();
|
||||
//TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
|
||||
//print("---- postion is ${position.latitude}, ${position.longitude}");
|
||||
gps.clear();
|
||||
gps.add(
|
||||
"-- lat : ${position.latitude}, lon : ${position.longitude} --");
|
||||
//gps.clear();
|
||||
//gps.add(
|
||||
// "-- lat : ${position.latitude}, lon : ${position.longitude} --");
|
||||
checkForCheckin(position.latitude, position.longitude);
|
||||
print("--- call check checkin");
|
||||
print("---- skip gps is ${skip_gps.toString()} ----");
|
||||
@ -583,10 +587,44 @@ class DestinationController extends GetxController {
|
||||
ever(indexController.connectionStatusName, connectionChanged);
|
||||
}
|
||||
|
||||
|
||||
void startGPSTimer() {
|
||||
// If a timer is already running, we first cancel it
|
||||
_GPStimer?.cancel();
|
||||
|
||||
// Start a new timer that fires every 3 seconds
|
||||
_timer = Timer.periodic(Duration(seconds: 3), (timer) async {
|
||||
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
|
||||
|
||||
if (is_gps_selected.value) {
|
||||
double czoom = indexController.rogMapController.zoom;
|
||||
indexController.rogMapController
|
||||
.move(LatLng(position.latitude, position.longitude), czoom);
|
||||
checkForCheckin(position.latitude, position.longitude);
|
||||
print("--- call check checkin");
|
||||
print("---- skip gps is ${skip_gps.toString()} ----");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void stopGPSTimer() {
|
||||
_GPStimer?.cancel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
positionStream?.cancel();
|
||||
_GPStimer?.cancel();
|
||||
super.onClose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
initGPS();
|
||||
|
||||
//initGPS();
|
||||
startGPSTimer();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ dependencies:
|
||||
sqflite: ^2.0.1
|
||||
get: ^4.6.5
|
||||
flutter_map: any
|
||||
geolocator: ^9.0.1
|
||||
geolocator: ^9.0.2
|
||||
permission_handler: ^10.0.0
|
||||
google_api_availability: ^5.0.0
|
||||
tuple: ^2.0.0
|
||||
|
||||
Reference in New Issue
Block a user