GeoCoordinateWatcher 仅在初始时间触发并且不再响应
我正在尝试获取设备的纬度/经度。这是我的代码:
private void button5_Click(object sender, EventArgs e)
{
// Create the watcher.
Watcher = new GeoCoordinateWatcher();
// Catch the StatusChanged event.
Watcher.StatusChanged += Watcher_StatusChanged;
// Start the watcher.
Watcher.Start();
}
private void Watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Ready)
{
// Display the latitude and longitude.
if (Watcher.Position.Location.IsUnknown)
{
MessageBox.Show("Unknown latitude and longitude.");
}
else
{
GeoCoordinate location = Watcher.Position.Location;
MessageBox.Show($"Lat: {location.Latitude} Long: {location.Longitude}");
}
}
}
当我单击按钮触发事件时,这是我获得纬度/经度读数的唯一时间。该事件不会再次触发,我在其上放置了一个断点,除非再次单击该按钮。我是否误解了这段代码应该如何工作?难道它不应该在纬度/经度发生变化时触发吗?
I'm trying to get the lat/lon of the device. Here is my code:
private void button5_Click(object sender, EventArgs e)
{
// Create the watcher.
Watcher = new GeoCoordinateWatcher();
// Catch the StatusChanged event.
Watcher.StatusChanged += Watcher_StatusChanged;
// Start the watcher.
Watcher.Start();
}
private void Watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Ready)
{
// Display the latitude and longitude.
if (Watcher.Position.Location.IsUnknown)
{
MessageBox.Show("Unknown latitude and longitude.");
}
else
{
GeoCoordinate location = Watcher.Position.Location;
MessageBox.Show(quot;Lat: {location.Latitude} Long: {location.Longitude}");
}
}
}
When I click the button to fire the event is the only time I'm getting a lat/lon reading. The event is not firing again, I put a break point on it, unless I click the button again. Am I misunderstanding how this code should work? Shouldn't it fire off any time that the lat/lon changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论