C# Windows Phone 8上的gps跟踪性能问题
为一个遛狗的朋友制作了一个快速应用程序,他想知道自己能走多远,速度和准确度。无论如何,我让应用程序只跟踪距离和位置与计时器。一切正常,但当每8秒更新屏幕上的统计数据时,似乎存在性能问题,因为时间将暂停,然后跳2秒,好像说更新部分需要1秒或2秒 这是密码C# Windows Phone 8上的gps跟踪性能问题,c#,gps,location,windows-phone,C#,Gps,Location,Windows Phone,为一个遛狗的朋友制作了一个快速应用程序,他想知道自己能走多远,速度和准确度。无论如何,我让应用程序只跟踪距离和位置与计时器。一切正常,但当每8秒更新屏幕上的统计数据时,似乎存在性能问题,因为时间将暂停,然后跳2秒,好像说更新部分需要1秒或2秒 这是密码 List<GeoCoordinate> Locations; Geolocator Locator = new Geolocator(); Locator.DesiredAccuracy = PositionAccuracy.High
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 thread-wrap Dispatcher.BeginInvoke上更新 大约持续时间,它应该会起作用
Deployment.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Duration = time.ToString(@"hh\:mm\:ss");
}
有什么问题?计时器不工作?或者GPS信号有一秒钟没有更新,下一秒钟又更新了?不,问题是当它更新统计数据时需要2秒钟。所以你得到00:08,然后它停止,然后它突然说00:10。所以问题是为什么更新速度慢?如果你读到,我使用的是在UI线程上执行的Dispatcher。而且这不是问题所在。