Flutter 位置欺骗破坏地理定位器?

Flutter 位置欺骗破坏地理定位器?,flutter,dart,location,flutter-dependencies,dart-pub,Flutter,Dart,Location,Flutter Dependencies,Dart Pub,我正在使用geolocator包获取设备的当前位置。我最近安装了一个位置来测试一些功能 然而,在使用spoofer时,地理定位器似乎坏了?每当我尝试获取位置时,它都不会返回位置 我如何解决这个问题?谢谢你的帮助 (问题是,即使在我卸载位置欺骗程序后,位置也不再返回。我的应用程序的GPS功能在设备上不再工作) 这是我每次尝试获取位置时调用的函数 Future<Position> getCurrentLocation() async { bool serviceEnabled;

我正在使用geolocator包获取设备的当前位置。我最近安装了一个位置来测试一些功能

然而,在使用spoofer时,地理定位器似乎坏了?每当我尝试获取位置时,它都不会返回位置

我如何解决这个问题?谢谢你的帮助

(问题是,即使在我卸载位置欺骗程序后,位置也不再返回。我的应用程序的GPS功能在设备上不再工作)

这是我每次尝试获取位置时调用的函数

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;
}

在我安装并使用位置欺骗应用程序之前,上述代码工作正常。因此,即使在卸载之后,该应用程序也不再工作,只是超时,因为未来不会重现。

在真实设备上使用欺骗应用程序可能会很困难,因为许多设备实施了阻止其工作的保护

在开发过程中,我将使用来自Android Studio(AVD)的虚拟仿真器,而不是使用来自真实设备的Spoofer应用程序

通过执行soo,您可以直接使用仿真器提供的定位工具

从图像中可以看到,该工具使您能够使用GPX或KML文件为设备提供位置

我发现这篇文章描述了如何构建自己的路线:

为虚拟设备提供位置的另一种方法是使用命令行工具Telnet

在过去,我能够编写一个python脚本,它使用Telnet为我的AVD提供gps位置


在我看来,这样你就可以更好地控制位置。

这不是一件好事吗(一个恶搞不起作用)?可能有人在porpoise上这么做了。问题是,在我使用位置欺骗的设备上,普通的GPS功能不再适用于我的应用程序。无论何时我尝试检索用户位置,未来都不会回来。如果你是一名开发人员,卸载你的Flatter应用程序并在真实和模拟设备上重复干净的安装对你来说应该不是问题。如果问题仍然存在,那么可能与spoofer应用程序无关。问题仍然存在,这就是我问这个问题的原因。如果我不太清楚,那么很抱歉,可能问题与Flatter无关。使用spoofer不是一个好的做法。GPS在谷歌地图等应用程序中有效吗?你试过模拟器吗?或其他不受欺骗影响的设备。其他应用程序工作正常。我的在我测试spoofer之前就可以用了。正如我在文章中提到的,基本的获取位置功能不再在我的设备上工作(而且只在我的设备上工作。我已经在其他设备上测试过该应用程序,它工作正常)。
                    getCurrentLocation().then((contents) {
                      print('getting location');
                      print(contents.latitude);
                      );
                    }, onError: (e) {}).timeout(const Duration(seconds: 5),
                        onTimeout: () {
                      callSnackbar('Error', 'Couldn\'t get location');
                    });