Windows Phone 8 - GPS定位速度

时间:2014-01-31 09:49:43

标签: c# windows-phone-7 windows-phone-8

我希望每次更新位置时都能获得gps速度。 现在我这样做:

Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 0;
geolocator.MovementThreshold = 100;

geolocator.PositionChanged += geolocator_PositionChanged;

void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
    Dispatcher.BeginInvoke(() =>
    {
        SpeedBlock.Text = args.Position.Coordinate.Speed.ToString();

        LatitudeTextBlock.Text = args.Position.Coordinate.Latitude.ToString("0.00");
        LongitudeTextBlock.Text = args.Position.Coordinate.Longitude.ToString("0.00");
    });
}

此代码适用于获取纬度和经度,但速度总是出错。 在仿真器速度上始终显示5.6 m / s。在设备上,它始终为0。

为什么呢?我做错了什么?

1 个答案:

答案 0 :(得分:3)

您是否查看了这篇文章http://www.geekchamp.com/articles/understanding-the-windows-phone-location-service-how-to-get-current-gps-coordinates

有注意事项:

  

海拔高度,课程和速度仅在您指定时才可用   您想要使用高精度的位置信息   GeoPositionAccuracy.High而不是GeoPositionAccuracy.Default和   从GPS接收器检索该数据。所以,如果你试试这个   使用默认精度的样本,您将获得海拔高度,速度的NaN   当然。不幸的是,虽然它更准确,精度更高   使用更多功率,可能需要更长时间来确定您的位置。如果你   正在室内测试你的应用程序,它可能仍然显示NaN的结果   高度,航向和速度,因GPS信号较弱。

另外请看一下这个例子:http://www.codeproject.com/Articles/521530/A-Windows-Phone-Run-Tracking-App-in-Lines-of 它显示了如何进行自己的步速计算 - 但这取决于应用程序的场景。