在 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 地图中显示基于 KML 文件的图钉?
另外,我想知道是否有一种方法可以为 KML 文件中的每个图钉提供 Onclick 事件。
目前我正在使用下面的代码,该代码可以工作文件,但我不确定如何使用基于 KML 的图钉来实现它
void BusStop8679_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
int id = 8679;
NavigationService.Navigate(new Uri("/DepartureBoard.xaml?ListingId=" + id, UriKind.Relative));
}
Currently i am using the following code to display locations on a map in my application:
//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);
This is very tedious as there are hundreds of locations to add, so I was thinking about displaying locations based on a KML file.
My question is how do I display pushpins based on a KML file in windows phone 7 Bing Maps?
Also, I would like to know if there is a way of having an Onclick event for each of these pushpins from the KML file.
Currently I am using the below code which works file, but I 'm not sure how I would implemented that with KML based pushpins
void BusStop8679_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
int id = 8679;
NavigationService.Navigate(new Uri("/DepartureBoard.xaml?ListingId=" + id, UriKind.Relative));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解析 KML 文件中的坐标(使用 RestSharp 或 XML 反序列化器会变得非常容易),然后使用 数据绑定 来绑定将列表坐标到视图,并使用 ItemTemplate< /a> 自定义图钉本身。
然后,您可以附加 点击事件。将
Tag
属性设置为{Binding}
,并在 Tap 元素中读出它,然后就可以访问您单击的元素了。Parse the coordinates in the KML file (using RestSharp or a XML de-serializer would make it very easy), then use databinding to bind the coordinate list to the view, and use a ItemTemplate to customize the pushpin itself.
You can then attach a event listener for the Tap event. Set the
Tag
property to{Binding}
, and read it out in the Tap element, and then you can access the element you clicked.