Information
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.Start Method

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)

public void Start()

Implements

IGeoPositionWatcher<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.

using System;
using System.Device.Location;

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

            public void GetLocationDataEvent()
            {
                this.watcher = new GeoCoordinateWatcher();
                this.watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
                this.watcher.Start();
            }

            void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
            {
                PrintPosition(e.Position.Location.Latitude, e.Position.Location.Longitude);
                // Stop receiving updates after the first one. 
                this.watcher.Stop();
            }

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, 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