Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

GeoCoordinateWatcher.OnPositionChanged Method (GeoPositionChangedEventArgs<GeoCoordinate>)

.NET Framework (current version)

Called when a PositionChanged event occurs.

Namespace:   System.Device.Location
Assembly:  System.Device (in System.Device.dll)

protected void OnPositionChanged(
	GeoPositionChangedEventArgs<GeoCoordinate> e

The following program shows how to subscribe to continuous updates from PositionChanged events.

using System;
using System.Device.Location;

namespace GetLocationEvent
    class Program
        static void Main(string[] args)
            CLocation myLocation = new CLocation();
            Console.WriteLine("Enter any key to quit.");
        class CLocation
            GeoCoordinateWatcher watcher;

            public void GetLocationEvent()
                this.watcher = new GeoCoordinateWatcher();
                this.watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
                bool started = this.watcher.TryStart(false, TimeSpan.FromMilliseconds(2000));
                if (!started)
                    Console.WriteLine("GeoCoordinateWatcher timed out on start.");

            void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
                PrintPosition(e.Position.Location.Latitude, e.Position.Location.Longitude);

            void PrintPosition(double Latitude, double Longitude)
                Console.WriteLine("Latitude: {0}, Longitude {1}", Latitude, Longitude);

.NET Framework
Available since 4.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2016 Microsoft