如何在Windows Phone中手动调用PositionChanged方法?

时间:2013-05-26 10:08:05

标签: windows-phone-7 windows-phone-8 windows-phone-7.1 windows-phone bing-maps

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

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

 {
   //do the stuff here
 }

现在当用户点击地图上的任何位置时,我想调用上面的方法并且每次都做同样的事情。 知道如何实现这个目标吗?

1 个答案:

答案 0 :(得分: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。我推荐这个解决方案,它比第一个更清洁。