在Bing Windows Phone 7中显示基于KML文件的位置

目前我使用以下代码在我的应用程序中显示地图上的位置:

//Bustop 8448 – Pushpin BusStop8448 = new Pushpin(); BusStop8448.Background = new SolidColorBrush(Colors.Red); BusStop8448.Location = new GeoCoordinate(-36.934608, 174.73016); BusStop8448.Content = "Bus Stop: 8448 "; BusStop8448.MouseLeftButtonUp += new MouseButtonEventHandler(BusStop8448_MouseLeftButtonUp); var BusStop8448Press = sender as Pushpin; this.Map.Children.Add(BusStop8448); 

这非常繁琐,因为要添加数百个位置,所以我在考虑根据KML文件显示位置。

我的问题是如何在Windows Phone 7 Bing Maps中显示基于KML文件的图钉?

此外,我想知道是否有一种方法可以从KML文件中为每个图钉创建一个Onclick事件。

目前我使用下面的代码工作文件,但我不知道如何用基于KML的图钉实现它

 void BusStop8679_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { int id = 8679; NavigationService.Navigate(new Uri("/DepartureBoard.xaml?ListingId=" + id, UriKind.Relative)); } 

解析KML文件中的坐标(使用RestSharp或XML反序列化器会使其变得非常简单),然后使用数据绑定将坐标列表绑定到视图,并使用ItemTemplate自定义图钉本身。

然后,您可以为Tap事件附加事件侦听器。 将Tag属性设置为{Binding} ,并在Tap元素中读取它,然后您可以访问您单击的元素。