Windows Phone 8上的gps跟踪性能问题
本文关键字:跟踪 性能 问题 gps 上的 Phone Windows | 更新日期: 2023-09-27 17:59:45
为一位遛狗的朋友制作了一个快速应用程序,他想知道自己走了多远,速度和高精度的东西。不管怎样,我用计时器让应用程序只跟踪距离和位置。一切正常,但当更新屏幕上的统计数据(每8秒执行一次)时,似乎存在性能问题,因为时间会暂停,然后跳2秒,好像在说更新部分需要1秒或2秒。
这是代码
List<GeoCoordinate> Locations;
Geolocator Locator = new Geolocator();
Locator.DesiredAccuracy = PositionAccuracy.High;
Locator.MovementThreshold = 1;
Locator.PositionChanged += Locator_PositionChanged;
DispatcherTimer _timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Tick += Timer_Tick;
_timer.Start();
long _startTime = System.Enviroment.TickCount;
private void Locator_PositionChanged(Geolocator sender, PostionChangedEventArgs args)
{
CurrentLocation = args.Position;
if(GetPositionTime >= 8) // Checks to see if 8 seconds has passed
{
Deployment.Current.Dispatcher.BeginInvoke(new Action(() =>
{
GeoCoordinate cord = new GeoCoordinate(CurrentLocation.Coordinate.Latitude,
CurrentLocation.Coordinate.Longitude);
if(Locations.Count > 0)
{
GeoCoordinate PreviousLocation = Locations.Last();
// This part will update the stats on the screen as a textbox is bound to
// DistanceMoved
DistanceMoved = cord.GetDistanceTo(PreviousLocation);
}
Locations.Add(cord);
}));
}
}
private void Timer_Tick(object sender, EventArgs e)
{
GetPositionTime++;
TimeSpan time = TimeSpan.FromMilliseconds(System.Enviroment.TickCount - _startTime);
// Update the timer on the screen
Duration = time.ToString(@"hh':mm':ss");
}
UI控件需要在UI线程包装Dispatcher.BeginInvoke上更新大约持续时间,它应该起作用。
Deployment.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Duration = time.ToString(@"hh':mm':ss");
}