4

I'm using the geolocator package to get the current location of a device. I recently installed a location Spoofer app to test some features .

However, upon using the spoofer, geolocator seems to break? It never returns a location whenever I try to get a location.

How do I resolve this issue? Thank you for your help!

(the problem is that the location no longer returns even after I uninstall the location spoofer. The GPS functions for my app no longer work on the device)

Heres the function I call whenever I try to get a location

Future<Position> getCurrentLocation() async {
  bool serviceEnabled;
  LocationPermission permission;
  Position position;
  // ignore: await_only_futures
  serviceEnabled = await Geolocator.isLocationServiceEnabled();
  if (!serviceEnabled) {
      // ignore: await_only_futures
    await requestLocation();
    serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      callSnackbar('Error', 'Location services are disabled');
      return Future.error('Location services are disabled.');
    }
  }

  permission = await Geolocator.checkPermission();
  if (permission == LocationPermission.deniedForever) {
    callSnackbar('Error',
        'Location permissions are permantly denied, we cannot request permissions');

    return Future.error(
        'Location permissions are permantly denied, we cannot request permissions.');
  }

  if (permission == LocationPermission.denied) {
    permission = await Geolocator.requestPermission();
    if (permission != LocationPermission.whileInUse &&
        permission != LocationPermission.always) {
      callSnackbar('Error',
          'Location permissions are denied (actual value: $permission)');
      return Future.error(
          'Location permissions are denied (actual value: $permission).');
    }
  }
  print('LOGIC');
  position = await Geolocator.getCurrentPosition();
  if (position == null) {
    print('null');
  } else {
    print('LOCATION');
    print(position);
  }
  return position;
}

and heres an example of me calling the function:

                    getCurrentLocation().then((contents) {
                      print('getting location');
                      print(contents.latitude);
                      );
                    }, onError: (e) {}).timeout(const Duration(seconds: 5),
                        onTimeout: () {
                      callSnackbar('Error', 'Couldn\'t get location');
                    });

the above code works fine until I install and use a location spoofer app. So even after the uninstall, the app no longer works and just timeouts because the future does not return.

Emmanuel
  • 315
  • 1
  • 3
  • 15

1 Answers1

1

Using a spoofer app on a real device could be difficult as many devices implement protections that block it from working.

While you are developing, instead of using a Spoofer app from a real device, I would use a Virtual emulator from Android Studio (AVD).

By doing soo you can use the Location tool directly provided with the emulator.

enter image description here

enter image description here

As you can see from the images, that tool enable you to use GPX or KML file to provide a location to your device.

I found this article which describe how you can build your own route: Here

Another way of providing location to a virtual device could be using a the command line tool Telnet.

I was able in the past to write a python script which uses Telnet to provide gps location to my AVD.

In that way you can have more control over the location, in my opinion.

L. Gangemi
  • 3,110
  • 1
  • 22
  • 47
  • The thing is, the normal GPS function no longer works for my app on the device I used the location spoofer on. Whenever I try to retrieve the users location, the future never returns. – Emmanuel Mar 19 '21 at 05:49
  • If you are a developer, it shouldn't be a problem for you to uninstall your flutter app and repeat a clean install on both the real and emulated device. If the problem still persists then maybe it is not related to the spoofer app. – L. Gangemi Mar 19 '21 at 11:55
  • The problem still persists, thats why I'm asking this question actually sorry if I wasn't clear enough – Emmanuel Mar 20 '21 at 10:21
  • Maybe the problem is not related to Flutter. Using spoofer is not a good practice. Does GPS works in apps like google maps? Have you tryed the emulator? Or another device which wasn't affected by the spoofer. – L. Gangemi Mar 20 '21 at 11:32
  • Other apps work fine. Mine used to work before I tested the spoofer. As mentioned in my post, the basic get location functions no longer work on my device (and only my device. I've tested the app on other devices and it works fine). – Emmanuel Mar 20 '21 at 15:16
  • If you post some code I'll try to replicate the error and then I could look for a solution – L. Gangemi Mar 20 '21 at 22:02
  • posted! Thank you for your efforts tho – Emmanuel Mar 22 '21 at 04:43