Display locations based on KML file in Bing Window

2020-07-27 15:38发布

问题:

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));           
}

回答1:

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.