我正在開發一個windows手機運動跟蹤器應用程序,它使用gps傳感器來計算跑步者跑過的距離,我正在使用geocoordinatewatcher類,將移動閾值設置爲100.但是,我發現我的即使設備保持靜止,也可以提供距離值。只有當設備改變其位置時,我的應用纔會給出距離。我在市場上的其他應用程序中發現了相同的錯誤,請告訴我我在哪裏做錯了?
我的代碼。GPS準確性問題
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
watcher.MovementThreshold = 150;
watcher.PositionChanged += watcher_PositionChanged;
watcher.Start();
{
latitudeCurrent = e.Position.Location.Latitude;
longitudeCurrent = e.Position.Location.Longitude;
if (stepCounter == 0)
{
latitudePrevious = latitudeCurrent;
longitudePrevious = longitudeCurrent;
distanceTravelled += Math.Round(Calculate(latitudePrevious,longitudePrevious,latitudeCurrent,longitudeCurrent),2);
txbDistanceTravelled.Text = distanceTravelled.ToString();
txbCalories.Text=string.Format("{0:f0}", distanceTravelled * 65);
stepCounter++;
var millisPerKilometer = (distanceTravelled) * (System.Environment.TickCount - _previousPositionChangeTick);
txbPace.Text = TimeSpan.FromMilliseconds(millisPerKilometer).ToString(@"mm\:ss");
double hrs = counterTick/3600;
if (!double.IsNaN((distanceTravelled/hrs)))
{
txbSpeed.Text = (distanceTravelled/hrs).ToString();
}
else
{
txbSpeed.Text = "0";
}
}
}
您是在室外還是在室內使用WiFi測試設備?如果你在室內,很可能你沒有使用GPS,因此失去了準確性,並切換到小區或wifi位置。也許啓用了一些記錄的調試信息,並帶你到外面散步的設備,看看你會得到什麼結果。 – LewisBenge