2012-09-17 24 views
0

我使用GeoCoordinateWatcher檢測的windows phone的logitude和緯度7PositionChanged事件GeoCoordinateWatcher在WP7

我做了以下

GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default); 
    // Add event handlers for StatusChanged and PositionChanged events 
     watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged); 
     watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged); 
     watcher.MovementThreshold = 100; 

     // Create A Timer for Getting the GPS Cooradinate every 10 seconds only 
     System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer(); 

     // Start the Location service in the First time when the Application run 
     StartLocationService(); 
     // 15 minutes the interval of timer 
     dt.Interval = new TimeSpan(0, 0, 0, 10, 0); 

     // Add the Tick Method for event Handler 
     dt.Tick += new EventHandler(Start_Service); 

     // Start the Timer 
     dt.Start(); 
    } 
在start_service方法

我打電話watcher.start

問題是,即使位置沒有改變,每10秒調用一次watcher_PositionChanged! ,我知道

watcher.MovementThreshold = 100; 

會當行駛距離爲100以上 watcher_PositionChanged方法被調用但是,這並沒有發生

注:我測試使用模擬器

回答

2

我的代碼如果我理解正確,則每隔10秒再啓動一次geowatcher,因此每10秒鐘重新啓動一次,併產生實際座標。

如果您想每10秒調用一次方法,只有當位置發生變化時,纔可以使用currentCoordinates和lastCoordinates值。您使用每個PositionChanged事件編寫currentCoordinates,每10秒測試一次是否與lastCoordinates不同。或更好,你可以使用Reactive Extensions來組合事件。

+0

但我設置watcher.MovementThreshold和我改變我的位置和positionChanged事件沒有被解僱 – Developer

相關問題