Export (0) Print
Expand All

GeoCoordinateWatcher.IGeoPositionWatcher(Of GeoCoordinate).PositionChanged Event

Indicates that the location data has changed.

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

'Declaration
Private Event PositionChanged As EventHandler(Of GeoPositionChangedEventArgs(Of GeoCoordinate))
	Implements IGeoPositionWatcher(Of GeoCoordinate).PositionChanged

Implements

IGeoPositionWatcher(Of T).PositionChanged

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

Imports System.Device.Location
Module GetLocationEvent
    Public Class CLocation
        Private WithEvents watcher As GeoCoordinateWatcher
        Public Sub GetLocationEvent()
            watcher = New System.Device.Location.GeoCoordinateWatcher()
            AddHandler watcher.PositionChanged, AddressOf watcher_PositionChanged
            Dim started As Boolean = watcher.TryStart(False, TimeSpan.FromMilliseconds(1000))

            If Not started Then
                Console.WriteLine("GeoCoordinateWatcher timed out on start.")
            End If 
        End Sub 

        Private Sub watcher_PositionChanged(ByVal sender As Object, ByVal e As GeoPositionChangedEventArgs(Of GeoCoordinate))
            PrintPosition(e.Position.Location.Latitude, e.Position.Location.Longitude)
        End Sub 

        Private Sub PrintPosition(ByVal Latitude As Double, ByVal Longitude As Double)
            Console.WriteLine("Latitude: {0}, Longitude {1}", Latitude, Longitude)
        End Sub 
    End Class 


    Public Sub Main()
        Dim myLocation As New CLocation()
        myLocation.GetLocationEvent()
        Console.WriteLine("Enter any key to quit.")
        Console.ReadLine()
    End Sub 

End Module

.NET Framework

Supported in: 4.5, 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft