【问题标题】:Location spoofer breaks geolocator?位置欺骗器破坏了地理定位器?
【发布时间】:2021-06-09 09:02:14
【问题描述】:

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

但是,在使用欺骗器时,地理定位器似乎坏了?每当我尝试获取位置时,它都不会返回位置。

我该如何解决这个问题?感谢您的帮助!

(问题是即使我卸载了位置欺骗器,位置也不再返回。我的应用程序的 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;
}

这是我调用该函数的示例:

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

在我安装和使用定位欺骗应用程序之前,上面的代码可以正常工作。因此,即使在卸载之后,该应用程序也不再工作,并且只是超时,因为未来不会返回。

【问题讨论】:

  • 这不是一件好事(欺骗者不起作用)吗?可能有人在海豚身上做过。

标签: flutter dart location flutter-dependencies dart-pub


【解决方案1】:

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

在您进行开发时,我不会使用来自真实设备的 Spoofer 应用,而是使用 Android Studio (AVD) 中的虚拟模拟器。

通过这样做,您可以使用模拟器直接提供的定位工具。

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

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

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

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

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

【讨论】:

  • 问题是,在我使用定位欺骗器的设备上,正常的 GPS 功能不再适用于我的应用程序。每当我尝试检索用户位置时,未来永远不会返回。
  • 如果您是开发人员,卸载您的 Flutter 应用并在真实设备和模拟设备上重复全新安装应该不是问题。如果问题仍然存在,则可能与欺骗应用程序无关。
  • 问题依然存在,所以我问这个问题其实很抱歉,如果我不够清楚
  • 可能问题与 Flutter 无关。使用欺骗器不是一个好习惯。 GPS 是否适用于谷歌地图等应用程序?你试过模拟器吗?或其他不受欺骗者影响的设备。
  • 其他应用运行良好。在我测试欺骗器之前,我的曾经工作过。正如我的帖子中提到的,基本的获取位置功能不再在我的设备上运行(而且只能在我的设备上运行。我已经在其他设备上测试了该应用程序,它运行良好)。
猜你喜欢
  • 2013-08-27
  • 2011-10-01
  • 2017-03-14
  • 2017-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多