C# 处理不精确、抖动的gps信号
我的目标是使用GPS测量我用手机移动的距离。我的问题是,结果不精确。我使用了以下代码来计算距离:C# 处理不精确、抖动的gps信号,c#,android,gps,xamarin,xamarin.android,C#,Android,Gps,Xamarin,Xamarin.android,我的目标是使用GPS测量我用手机移动的距离。我的问题是,结果不精确。我使用了以下代码来计算距离: public double getDistance(GeoCoordinate p1, GeoCoordinate p2) { double d = p1.Latitude * 0.017453292519943295; double num3 = p1.Longitude * 0.017453292519943295; double num4 = p2.Latitude *
public double getDistance(GeoCoordinate p1, GeoCoordinate p2)
{
double d = p1.Latitude * 0.017453292519943295;
double num3 = p1.Longitude * 0.017453292519943295;
double num4 = p2.Latitude * 0.017453292519943295;
double num5 = p2.Longitude * 0.017453292519943295;
double num6 = num5 - num3;
double num7 = num4 - d;
double num8 = Math.Pow(Math.Sin(num7 / 2.0), 2.0) + ((Math.Cos(d) * Math.Cos(num4)) * Math.Pow(Math.Sin(num6 / 2.0), 2.0));
double num9 = 2.0 * Math.Atan2(Math.Sqrt(num8), Math.Sqrt(1.0 - num8));
return (6376500.0 * num9);
}
这是我的OnLocationChanged
实现:
bool begin = true;
public void OnLocationChanged(Location location)
{
_aktuellerOrt = location;
//aktuellerOrt.Speed is always 0, so I cannot use that.
if (_aktuellerOrt == null)
{
//message
}
else
{
if (_aktuellerOrt.Accuracy > 70) //I found values around 130 to be more or less good
{
_locationText.Text = String.Format("{0}, {1}", _aktuellerOrt.Latitude, _aktuellerOrt.Longitude);
GeoJetzt = new GeoCoordinate();
GeoJetzt.Latitude = _aktuellerOrt.Latitude;
GeoJetzt.Longitude = _aktuellerOrt.Longitude;
if (beginn)
{
GeoVorher = new GeoCoordinate();
GeoVorher.Latitude = _aktuellerOrt.Latitude;
GeoVorher.Longitude = _aktuellerOrt.Longitude;
beginn = false;
}
else
{
double abstand = getDistance(GeoVorher, GeoJetzt);
weg += abstand;
if (weg >= 1)
_distanzText.Text = weg + " kilometers";
else
_distanzText.Text = (weg * 1000) + " meters";
_distanzText.Text += " (" + abstand + ", " + _aktuellerOrt.Accuracy + ")";
GeoVorher = new GeoCoordinate();
GeoVorher.Latitude = _aktuellerOrt.Latitude;
GeoVorher.Longitude = _aktuellerOrt.Longitude;
}
}
else
_locationText.Text = "Too coarse, now " + _aktuellerOrt.Accuracy + ".";
}
}
问题是,在不移动手机的情况下,我会在公里范围内获取和的值
不精确信号的最佳实践是什么?我的目标是在慢跑或跑步时测量距离,因此10-16 km/h。步行不是10 km/h,更像是5 km/h(),无论如何,你应该使用低通滤波器。你可以试试这个卡尔曼滤波器:看看效果是否更好。@Cheesebaron你建议Q_米/u秒的值是多少?你读过那个家伙提供的文本了吗?他做了很多努力来创造这个答案,甚至给了你一个关于Q值应该使用的答案。