1
爲一位走過他的狗的朋友提供了一個快速應用程序,他想知道他走多遠,速度和準確性高。無論如何,我使用計時器跟蹤應用程序的距離和位置。一切正常,但當更新屏幕上的統計數據(每8秒執行一次)時,似乎會出現性能問題,因爲時間會暫停,然後跳轉2秒,好像說更新部分正在進行第二次或2.Windows Phone 8上的gps跟蹤性能問題
下面是代碼
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");
}
什麼是問題?計時器不起作用?或者GPS信號丟失了一秒的更新,並在下一次更新? – AlexWien 2013-02-15 17:25:09
沒問題,當它更新統計數據時,需要2秒鐘才能完成。所以你得到00:08然後停下來,然後突然說00:10。所以問題是爲什麼更新緩慢? – Gaz83 2013-02-15 21:30:03