【发布时间】:2019-09-25 09:50:27
【问题描述】:
我正在尝试在我的应用上使用实时 GPS 跟踪来跟踪用户的动作,但整个事情是如此不一致。我正在使用两个推荐的库来实现这一点。这是我正在使用的两个库:
这就是问题所在。两个库都返回坐标,但每当我静止不动时,GPS 坐标就会不断跳来跳去。我真的把我的手机放在桌子上,我会看到这两个图书馆每秒都会给我不同的坐标,即使我的手机已经死了。我会说坐标通常在 10 米半径内,但它绝对会影响我的核心应用程序功能,因为我至少需要准确性或一致性。我很可能错过了一些东西,如果可以的话,请有人帮忙。这是我使用这两个库的代码:
位置库:
var location = new Location();
location.onLocationChanged().listen((LocationData currentLocation) {
print("Coord: ${currentLocation.latitude} ${currentLocation.longitude}");
_approachingGate
.getApproachingGate(
Position(
latitude: currentLocation.latitude,
longitude: currentLocation.longitude),
_userGates,
distance: 0)
.then((Map<String, Object> value) {
_nearbyGate = value[Constants.GATE];
notifyListeners();
});
});
地理定位库:
var geoLocator = Geolocator();
var locationOptions = LocationOptions(
accuracy: LocationAccuracy.bestForNavigation,);
Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
_approachingGate
.getApproachingGate(position, _userGates,distance: 8)
.then((Map<String, Object> value) {
_nearbyGate = value[Constants.GATE];
notifyListeners();
});
_positionStream = geoLocator
.getPositionStream(locationOptions)
.listen((Position position) {
print("Coord: ${position.latitude} ${position.longitude}");
_position = position;
var x = 2.0;
_approachingGate
.getApproachingGate(position, _userGates,distance: x)
.then((Map<String, Object> value) {
_nearbyGate = value[Constants.GATE];
notifyListeners();
});
GeoLocator 库允许我使用distanceFilter 仅在移动一定距离后进行更新,并且出于某种原因,它仅在需要时才起作用。
这是我刚刚得到的一些输出,当时我正忙着打字,我的设备还在桌子上。
I/flutter ( 7705): Coord: -26.1010019 28.0388391
I/flutter ( 7705): Coord: -26.101002 28.0388395
I/flutter ( 7705): Coord: -26.1010019 28.0388403
I/flutter ( 7705): Coord: -26.1010018 28.0388407
I/flutter ( 7705): Coord: -26.1010018 28.0388393
I/flutter ( 7705): Coord: -26.1010026 28.0388364
I/flutter ( 7705): Coord: -26.1010022 28.0388392
I/flutter ( 7705): Coord: -26.101002 28.0388393
I/flutter ( 7705): Coord: -26.1010021 28.0388405
I/flutter ( 7705): Coord: -26.1010024 28.03884
I/flutter ( 7705): Coord: -26.1010025 28.038839
I/flutter ( 7705): Coord: -26.1010022 28.0388383
I/flutter ( 7705): Coord: -26.1010423 28.0388409
I/flutter ( 7705): Coord: -26.1010033 28.0388375
【问题讨论】:
-
这是由于 GPS 卫星运动导致数据倾斜。任何没有这个问题的应用程序只是简单地对这些结果进行排序和平滑。例如,下次你去散步时,使用路线追踪器,并保持静止约 5 分钟。你可能会看到一团乱七八糟的东西。
-
@spongyboss 你找到解决这个位置问题的方法了吗?实际上,我也面临同样的问题。
标签: flutter dart geolocation location