Location spoofer breaks geolocator?

Viewed 122

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.

1 Answers

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.

Related