Use Geolocation in C#
look at the
GeoCoordinateWatcher
class which is defined in the System.Device
assemblyThe GeoCoordinateWatcher class supplies coordinate-based location data from the current location provider. The current location provider is prioritized as 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. 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.
Usage example :
static void Main(string[] args)
{
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
watcher.StatusChanged += (sender, e) =>
{
Console.WriteLine("new Status : {0}", e.Status);
};
watcher.PositionChanged += (sender, e) =>
{
Console.WriteLine("position changed. Location : {0}, Timestamp : {1}",
e.Position.Location, e.Position.Timestamp);
};
if(!watcher.TryStart(false, TimeSpan.FromMilliseconds(5000)))
{
throw new Exception("Can't access location");
}
Console.ReadLine();
}
I think this class relies on the same mechanism than the one use by Internet Explorer.
When you will use it, you will have an icon in your system notification tray telling that location has recently been accessed.
No comments:
Post a Comment