gpt4 book ai didi

Android GPS在计算距离的精度问题

转载 作者:行者123 更新时间:2023-11-29 21:13:43 27 4
gpt4 key购买 nike

我相信这个问题是众所周知的。

那么我的问题是什么?

我正在编写一个应用程序,该应用程序使用 GPS 提供程序来查找用户的位置并计算从用户到终点的距离。这工作正常。但是出现了一个问题:

问题详情:

如果您使用我的应用程序在城市中四处走动,它会为您提供一些距离数字,但是……距离在不断变化。无论我是否朝目的地移动,距离都会变高或变低(计算的距离值是从高到低“跳跃”,反之亦然)之前的距离数,但逻辑上它应该越来越低.我认为这是因为 GPS 信号有时会丢失或微弱,无法正确计算距离。

我需要什么帮助?

我想知道有没有一种方法可以过滤从 GPS 接收到的坐标,这样我可以获得更准确的距离数字,这样当我向终点移动时,距离就会被正确计算(尽可能不必是 100%正确)并且不要疯狂地上下变化。

如何获取坐标并计算距离:

public void onLocationChanged(Location location) 
{
txtLat = (TextView) findViewById(R.id.currentCoordinatesView);
clat = location.getLatitude();
clong = location.getLongitude();

Location location1 = new Location("Start");
location1.setLatitude(clat);
location1.setLongitude(clong);

Location locationB = new Location("Finish");

locationB.setLatitude(endLatitude); //endpoint coordinates
locationB.setLongitude(endLongitude);

distance = location1.distanceTo(locationB); //calculate the distance

TextView TextDistance = (TextView)findViewById(R.id.TextDistance);
TextDistance.setText(new DecimalFormat("##,###,###.##").format(distance)+" m");

CurLat = location.getLatitude();
CurLong = location.getLongitude();

最佳答案

可以通过保存最后的(比如 10 个)位置对象并根据这些对象进行计算来进一步改进以下答案。例如,如果最后 10 个位置表明用户正以 1m/s 的速度向目标移动,那么表明跳跃 5 米的新位置很可能不准确,应该忽略。

要过滤一些偏离的 GPS 更新,你可以简单地做这样的事情(3 代表位置相对于你的实际位置应该有多准确,并且可以调整):

    public void onLocationChanged(Location location) 
{
if (location.hasAccuracy() && location.getAccuracy() < 3) {
txtLat = (TextView) findViewById(R.id.currentCoordinatesView);
clat = location.getLatitude();
clong = location.getLongitude();

Location location1 = new Location("Start");
location1.setLatitude(clat);
location1.setLongitude(clong);

Location locationB = new Location("Finish");

locationB.setLatitude(endLatitude); //endpoint coordinates
locationB.setLongitude(endLongitude);

distance = location1.distanceTo(locationB); //calculate the distance

TextView TextDistance = (TextView)findViewById(R.id.TextDistance);
TextDistance.setText(new DecimalFormat("##,###,###.##").format(distance)+" m");

CurLat = location.getLatitude();
CurLong = location.getLongitude();
}
}

以下是精度度量的定义:Location getAccuracy()

Get the estimated accuracy of this location, in meters. We define accuracy as the radius of 68% confidence. In other words, if you draw a circle centered at this location's latitude and longitude, and with a radius equal to the accuracy, then there is a 68% probability that the true location is inside the circle.

In statistical terms, it is assumed that location errors are random with a normal distribution, so the 68% confidence circle represents one standard deviation. Note that in practice, location errors do not always follow such a simple distribution.

This accuracy estimation is only concerned with horizontal accuracy, and does not indicate the accuracy of bearing, velocity or altitude if those are included in this Location.

If this location does not have an accuracy, then 0.0 is returned. All locations generated by the LocationManager include an accuracy.

关于Android GPS在计算距离的精度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22010189/

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