Thanos Rom
Thanos Rom

Reputation: 311

Fused Location does not work when i turn GPS off , it does not work with Wifi or cellular data?

Ive tried to disable GPS and try it on virtual device but also in a real device to see if im eable to make some location updates .

I still dont get any location updates with closed GPS , any idea why ? In android docs wifi or cellular data must give me the position updates right ?

Here is my code :

import 'dart:async';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:geolocator/geolocator.dart';

@pragma('vm:entry-point')
Future<void> onStart(ServiceInstance service) async {
  StreamSubscription<Position>? positionStreamSubscription;
  late LocationSettings locationSettings;
  locationSettings = AndroidSettings(
    accuracy: LocationAccuracy.high,
    forceLocationManager: false,
    intervalDuration: const Duration(milliseconds: 500),
    //distanceFilter: 50,
  );
  Geolocator.getPositionStream(locationSettings: locationSettings);

  Timer.periodic(Duration(seconds: 20), (Timer timer) async {
    positionStreamSubscription?.cancel();

    try {
      positionStreamSubscription = Geolocator.getPositionStream(
              locationSettings:
                  AndroidSettings(intervalDuration: Duration(seconds: 1)))
          .listen((Position position) async {
        double geofenceLatitude = xxxxxx;
        double geofenceLongitude = xxxxx;
        double geofenceRadius = 60;

        double distance = await Geolocator.distanceBetween(
          position.latitude,
          position.longitude,
          geofenceLatitude,
          geofenceLongitude,
        );

        if (distance <= geofenceRadius) {
          print('Inside geofence 100');
          // positionStreamSubscription?.cancel();
          // await service.stopSelf();
        } else {
          print('Outside geofence 100');
        }
      });
    } catch (e) {
      print(e);
    }

  });
}

Upvotes: 0

Views: 95

Answers (0)

Related Questions