【发布时间】: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