Supplies location data that is based on latitude and longitude coordinates.
| C# | Visual Basic |
public sealed class GeoCoordinateWatcher : IDisposable, INotifyPropertyChanged, IGeoPositionWatcher<GeoCoordinate>
Public NotInheritable Class GeoCoordinateWatcher _ Implements IDisposable, INotifyPropertyChanged, IGeoPositionWatcher(Of GeoCoordinate)
| All Members | Constructors | Methods | Properties | Events | |
| Icon | Member | Description |
|---|---|---|
| GeoCoordinateWatcher()()()() |
Initializes a new instance of GeoCoordinateWatcher.
| |
| Equals(Object) | (Inherited from Object.) | |
| Finalize()()()() |
Free resources and perform other cleanup operations before the GeoCoordinateWatcher is reclaimed by garbage collection.
(Overrides Object.Finalize()()()().) | |
| GetHashCode()()()() |
Serves as a hash function for a particular type.
(Inherited from Object.) | |
| GetType()()()() |
Gets the Type of the current instance.
(Inherited from Object.) | |
| MemberwiseClone()()()() |
Creates a shallow copy of the current Object.
(Inherited from Object.) | |
| MovementThreshold |
The distance that must be moved, in meters relative to the coordinate from the last PositionChanged event, before the location provider will raise another PositionChanged event.
| |
| Position |
Gets the GeoCoordinate that indicates the current location.
| |
| PositionChanged |
Indicates that the latitude or longitude of the location data has changed.
| |
| PropertyChanged | ||
| Start()()()() |
Initiate the acquisition of data from the current location provider.
This method enables PositionChanged events and allows access to the Position property.
| |
| Start(Boolean) |
Initiate the acquisition of data from the current location provider.
This method enables PositionChanged events and allows access to the Position property.
| |
| Status |
Gets the current status of the GeoCoordinateWatcher.
| |
| StatusChanged |
Indicates that the status of the GeoCoordinateWatcher object has changed.
| |
| Stop()()()() |
Stops the GeoCoordinateWatcher from providing location data and events.
| |
| ToString()()()() | (Inherited from Object.) | |
| TryStart(Boolean, TimeSpan) |
Initiates the acquisition of data from the current location provider. This method returns synchronously.
|
Equivalent to System.Device.Location.GeoCoordinateWatcher in the .NET Framework 4
The GeoCoordinateWatcher class supplies coordinate-based location data from the current location provider, which is the location provider that is currently prioritized the highest on the computer, based on a number of factors such as the age and accuracy of the data from all providers, the accuracy requested by location applications, and the power consumption and performance impact associated with the location provider. Currently only a GPS provider is supported on .NET Compact Framework platforms.To begin accessing location data, create a GeoCoordinateWatcher and call Start()()()() or TryStart(Boolean, TimeSpan) to initiate the acquisition of data from the current location provider.
The Status property can be checked to determine if data is available. If data is available, you can get the location once from the Position property, or receive continuous location updates by handling the PositionChanged event.
| Platforms Supported | |
|---|---|
| Windows Mobile | Windows Mobile Version 5.0 and later |
| Windows Embedded Compact | Windows Embedded Compact 6.0 and later |
The following program demonstrates how to create a GeoCoordinateWatcher and start acquiring data using an initialization timeout.
It prints the location's coordinates, if known.
CopyC#
using System; using System.Device.Location; namespace GetLocationProperty { class Program { static void Main(string[] args) { GetLocationProperty(); } static void GetLocationProperty() { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(); // Do not suppress prompt, and wait 1000 milliseconds to start. watcher.TryStart(false, TimeSpan.FromMilliseconds(1000)); GeoCoordinate coord = watcher.Position.Location; if (coord.IsUnknown != true) { Debug.WriteLine("Lat: {0}, Long: {1}", coord.Latitude, coord.Longitude); } else { Debug.WriteLine("Unknown latitude and longitude."); } } } }
The following program demonstrates how to receive continuous location updates by subscribing to PositionChanged events.
CopyC#
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) { Debug.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) { Debug.WriteLine("Latitude: {0}, Longitude {1}", Latitude, Longitude); } } } }
| Object | |
| GeoCoordinateWatcher | |