【发布时间】:2015-07-10 09:43:15
【问题描述】:
我写了一段 c# 代码来获取我的粗略位置。
该程序将在没有 GPS 传感器的笔记本电脑上运行。
namespace WindowsFormsApplication1
{
class Class1
{
private GeoCoordinateWatcher watcher;
public void GetLocationDataEvent()
{
watcher = new System.Device.Location.GeoCoordinateWatcher();
watcher.PositionChanged += watcher_PositionChanged;
watcher.Start();
}
private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
String lat = e.Position.Location.Latitude.ToString();
String lon = e.Position.Location.Longitude.ToString();
MessageBox.Show(lat + "+" + lon);
// Stop receiving updates after the first one.
watcher.Stop();
}
}
}
嗯,它有效。但它给了我一个距离我的位置近 30 公里的坐标。有没有其他方法可以使它更准确?我可以承受大约 1 或 2 公里的误差,但这太过分了。
【问题讨论】:
标签: c# geolocation