0

我有以下事件,该事件会在 geocoordinatewatcher 对象位置更改事件时触发。

 void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)

 {
   //do the stuff here
 }

现在,当用户单击地图上的任何位置时,我想调用上述方法并每次都执行相同的操作。知道如何实现这一目标吗?

4

1 回答 1

4

手动调用您的事件处理程序:

var position = new GeoPosition<GeoCoordinate>(DateTimeOffset.Now, new GeoCoordinate(32, 64));

this.watcher_PositionChanged(this, new GeoPositionChangedEventArgs<GeoCoordinate>(position));

或者重写您的事件处理程序以将逻辑放在另一个方法中,然后调用它:

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    this.UpdatePosition(e.Position);
}

private void UpdatePosition(GeoCoordinate coordinates)
{
    // Do the stuff here
}

这样,您只需在需要UpdatePosition时打电话。我推荐这个解决方案,它比第一个更干净。

于 2013-05-26T10:18:53.700 回答