0

I'm using GeoCoordinateWatcher to detect the logitude and latitude in windows phone 7

I did the following

 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();
    }

in start_service method I'm calling watcher.start

The problem is that watcher_PositionChanged is called every 10 seconds even if the location didn't change !!! and I knew that

watcher.MovementThreshold = 100;

will watcher_PositionChanged method be called when the traveled distance is 100 or more But this didn't happen

NOTE: I'm testing my code using emulator

1 Answer 1

2

If I understand it correctly you start the geowatcher every 10 seconds again so every 10 seconds it is restarted and yields the actual coordinates.

If you want to call a method every 10 seconds only when the position has changed, you can have a currentCoordinates and lastCoordinates value. You write the currentCoordinates with each PositionChanged event and every 10 seconds test if it differs from lastCoordinates. or better, you can use Reactive Extensions to combine events.

Sign up to request clarification or add additional context in comments.

1 Comment

but I'm setting watcher.MovementThreshold and I change my position and the positionChanged event is not fired

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.