GeoCoordinateWatcher.OnPositionChanged Method (GeoPositionChangedEventArgs(Of GeoCoordinate))

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Called when a PositionChanged event occurs.

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

Protected Sub OnPositionChanged (
	e As GeoPositionChangedEventArgs(Of GeoCoordinate)


Type: System.Device.Location.GeoPositionChangedEventArgs(Of GeoCoordinate)

A GeoPositionChangedEventArgs(Of T) object that contains the new location.

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()
        Console.WriteLine("Enter any key to quit.")
    End Sub

End Module

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