2011-09-16 52 views
1

目前我使用下面的代碼在我的應用程序中顯示地圖上的位置:顯示位置7

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

回答

3

解析KML文件的座標(使用RestSharp或XML解串器會使它變得非常簡單),然後使用databinding將座標列表綁定到視圖,並使用ItemTemplate來自定義圖釘本身。

然後,您可以附加Tap event的事件偵聽器。將Tag屬性設置爲{Binding},並在Tap元素中將其讀出,然後可以訪問您單擊的元素。