gpt4 book ai didi

java - GPS 纬度和经度随机显示非常不准确的结果

转载 作者:行者123 更新时间:2023-12-01 15:19:30 25 4
gpt4 key购买 nike

我正在监听我的手机 GPS,并在每次调用 onLocationChanged 时将纬度和经度发布到我的网络服务。我的问题是,在大约 2% 的帖子中,它显示的结果非常不准确(相差几英里)。我应该在发布之前检查我的 location 对象的准确性吗?或者您还有其他建议吗?谢谢!

public void onLocationChanged(Location location) {
locationManager.removeUpdates(networkLocationListener);

textView.setText(textView.getText().toString() + "New GPS location: "
+ String.format("%9.6f", location.getLatitude()) + ", "
+ String.format("%9.6f", location.getLongitude()) + "\n");

//float accuracy = location.getAccuracy(); check this value?

postLocationToWebservice(location);
}

最佳答案

这是使用 Android 位置服务时的一个非常常见的问题。您可以引入一些检查来确保仅将准确的位置发布到您的网络服务。

1.比较所有定位服务的准确性。

2.定义精度的最小限制和时间的最大限制。(因为有时获取的位置是准确的,但它是旧的)。

检查此代码 fragment 并进行必要的更改以完成您想要的任务。请确保您做了检查算法准确性的日志构建。

List<String> matchingProviders = myLocation.lm.getAllProviders();
for (String provider: matchingProviders)
{
Location location = myLocation.lm.getLastKnownLocation(provider);
if (location != null) {
float accuracy = location.getAccuracy();
long time = location.getTime();

if ((time > minTime && accuracy < bestAccuracy)) {
bestResult = location;
bestAccuracy = accuracy;
bestTime = time;
}
else if (time < minTime && bestAccuracy == Float.MAX_VALUE && time > bestTime) {
bestResult = location;
bestTime = time;
}
}
}

关于java - GPS 纬度和经度随机显示非常不准确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11155160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com