本文整理汇总了C#中System.Device.Location.GeoCoordinateWatcher类的典型用法代码示例。如果您正苦于以下问题:C# GeoCoordinateWatcher类的具体用法?C# GeoCoordinateWatcher怎么用?C# GeoCoordinateWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeoCoordinateWatcher类属于System.Device.Location命名空间,在下文中一共展示了GeoCoordinateWatcher类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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)
{
Console.WriteLine("Lat: {0}, Long: {1}",
coord.Latitude,
coord.Longitude);
}
else
{
Console.WriteLine("Unknown latitude and longitude.");
}
}
}
}
示例2: Main
//引入命名空间
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)
{
Console.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)
{
Console.WriteLine("Latitude: {0}, Longitude {1}", Latitude, Longitude);
}
}
}
}