Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
IGeoPositionWatcher(GeoCoordinate).PositionChanged Event

GeoCoordinateWatcher.IGeoPositionWatcher<GeoCoordinate>.PositionChanged Event

.NET Framework 4.6 and 4.5

Indicates that the location data has changed.

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

event EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>> IGeoPositionWatcher<GeoCoordinate>.PositionChanged

Implements

IGeoPositionWatcher<T>.PositionChanged

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();
            myLocation.GetLocationEvent();
            Console.WriteLine("Enter any key to quit.");
            Console.ReadLine();            
        }
        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

Supported in: 4.6, 4.5, 4
Show:
© 2015 Microsoft