我正在开发一个 Windows 手机运动追踪器应用程序,它使用 gps 传感器来计算跑步者所经过的距离,我使用 geocoordinatewatcher 类,将运动阈值设置为 100。但是,我发现我的应用程序即使在设备保持静止。只有当设备改变位置时,我的应用才应该给出距离。我在市场上的其他应用程序中发现了相同的错误,请告诉我我哪里做错了?
我的代码。
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";
}
}
}