Export (0) Print
Expand All

GeoCoordinateWatcher.Start Method

.NET Framework 4.6 and 4.5

Initiate the acquisition of data from the current location provider. This method enables PositionChanged events and allows access to the Position property.

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

'Declaration
Public Sub Start

Implements

IGeoPositionWatcher(Of T).Start

Calling this method will initiate the acquisition of data from the current location provider. The current location provider is selected based on factors such as the age and accuracy of the data from all providers, the accuracy requested by the application or applications, and the power consumption and performance impact associated with the location provider. The current location provider might change over time, for instance, when a GPS device loses its satellite signal indoors and a Wi-Fi triangulation provider becomes the most accurate provider on the computer.

If the current prioritized location provider does not have data when the Start method is called, it will start to acquire data. If the permissions have been granted to the client when the data becomes available, data can be accessed synchronously, and will be delivered asynchronously if events are being handled.

If the Windows 7 Sensor and Location platform is disabled when Start is called, Start will immediately return, PositionChanged events will not be raised, and the location returned by the Location property of Position will contain Unknown.

If the current prioritized location provider does have data, it will be available synchronously immediately, and will be delivered asynchronously if events are being handled.

If the calling application does not have permissions to access data from a location provider, the user will be prompted with a dialog box to either grant or deny permission. The dialog box will be modeless.

The following program handles the first location update that occurs after Start is called.

Imports System.Device.Location
Module GetLocationEvent
    Public Class CLocation
        Private WithEvents watcher As GeoCoordinateWatcher
        Public Sub GetLocationDataEvent()
            watcher = New System.Device.Location.GeoCoordinateWatcher()
            AddHandler watcher.PositionChanged, AddressOf watcher_PositionChanged
            watcher.Start()

        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)
            ' Stop receiving updates after the first one.
            watcher.Stop()
        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.GetLocationDataEvent()
        Console.WriteLine("Enter any key to quit.")
        Console.ReadLine()
    End Sub 

End Module

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft