.NET 4.0 中关于访问传感器状态进行了封装。在.NET4.0 beta2中我们可以用GeoLocationProvider。但是现在我们可以方便的使用GeoCoordinateWatcher类进行获知。较以往的GeoLocationProvider现在的GeoCoordinateWatcher结构如下:
具体代码如下:using System;
using System.Device.Location;
namespace LocationStatusChange
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Outputting location updates, press any key to exit...");
LocationWatcher watcher = new LocationWatcher();
Console.ReadKey();
}
}
class LocationWatcher
{
private GeoCoordinateWatcher provider;
public LocationWatcher()
{
this.provider = new GeoCoordinateWatcher();
this.provider.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(provider_StatusChanged);
this.provider.Start();
}
void provider_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
Console.WriteLine("LocationStatus: " + e.Status.ToString());
}
}
}
namespace LocationStatusChange
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Outputting location updates, press any key to exit...");
LocationWatcher watcher = new LocationWatcher();
Console.ReadKey();
}
}
class LocationWatcher
{
private GeoCoordinateWatcher provider;
public LocationWatcher()
{
this.provider = new GeoCoordinateWatcher();
this.provider.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(provider_StatusChanged);
this.provider.Start();
}
void provider_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
Console.WriteLine("LocationStatus: " + e.Status.ToString());
}
}
}