You appear to be using it wrong. Furthermore, you can't use
MessageBox
to display the position because you'll be forced to keep hitting OK to dismiss the dialog.
private GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
private bool watcherStarted = false;
public void MakeCoordWatcher(int seconds)
{
if (!eventWatched)
{
this.watcherwatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
this.watcherStarted = this.watcher.TryStart(false, TimeSpan.FromMilliseconds(seconds*1000));
if (!started)
{
MessageBox.Show("GeoCoordinateWatcher timed out on start.");
}
}
}
private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
Debug.WriteLine("Lat: {0}, Long {1}", e.Position.Location.Latitude, e.Position.Location.Longitude);
}
How you display the watcher updates is up to you, and since you're using
MessageBox
, I'm assuming the app has a UI, so I would probably create a status bar that is updated by the event handler. Since I have no idea how your app is architechted, I leave that decision up to you.