2015-12-21 178 views
0

當前當我加載我的程序時,Bing地圖只會將第一個圖釘加載到地圖上,對於我的示例,我有4個圖釘,應用程序加載時應顯示圖釘,添加爲了使它完成所有四個。在Bing地圖上顯示多個圖釘WPF

另外我有幾個問題,如果你不介意回答

我需要使用一個循環的每個位置?

我必須給每個人一個個人的名字嗎? (Pin)

我可以鏈接訪問數據庫而不是複製位置嗎?

單擊按鈕時是否可以隱藏或刪除圖釘?

Dim Pin = New Microsoft.Maps.MapControl.WPF.Pushpin() 
    UserControl11.BingMap.Children.Add(Pin) 

    Pin.Location = (New Location(55.852663, -2.3889276)) 
    Pin.Location = (New Location(55.956023, -3.1607265)) 
    Pin.Location = (New Location(54.840279, -3.2886766)) 
    Pin.Location = (New Location(52.819511, -1.8851815)) 
+0

您只設置單次圖釘位置的四次。創建四個Pushpins實例,而不是一個,並將它們全部添加到地圖中。 – Clemens

+0

所以我應該只複製4次不同名稱的兩行代碼,或者有一個簡短的方法嗎? – Gaudreau95

+0

嘗試一下。這是學習編程的方式。 – Clemens

回答

1

如果只是要創建這些4針,那麼你可以使用下面的代碼:

Dim Pin = New Microsoft.Maps.MapControl.WPF.Pushpin() 
Pin.Location = (New Location(55.852663, -2.3889276)) 
UserControl11.BingMap.Children.Add(Pin) 

Dim Pin2 = New Microsoft.Maps.MapControl.WPF.Pushpin() 
Pin2.Location = (New Location(55.956023, -3.1607265)) 
UserControl11.BingMap.Children.Add(Pin2) 

Dim Pin3 = New Microsoft.Maps.MapControl.WPF.Pushpin() 
Pin3.Location = (New Location(54.840279, -3.2886766)) 
UserControl11.BingMap.Children.Add(Pin3) 

Dim Pin4 = New Microsoft.Maps.MapControl.WPF.Pushpin() 
Pin4.Location = (New Location(52.819511, -1.8851815)) 
UserControl11.BingMap.Children.Add(Pin4) 

另外,如果您的位置數據發生了變化,或者你有一個數組/列表位置信息,您可以循環,創建圖釘並將它們添加到地圖中,如下所示:

Dim myLocations(4) As Location 
myLocations(0) = New Location(55.852663, -2.3889276) 
myLocations(1) = New Location(55.956023, -3.1607265) 
myLocations(2) = New Location(54.840279, -3.2886766) 
myLocations(3) = New Location(52.819511, -1.8851815) 

For index = 0 to myLocations.Length - 1 
    Dim Pin = New Microsoft.Maps.MapControl.WPF.Pushpin() 
    Pin.Location = myLocations(index) 
    UserControl11.BingMap.Children.Add(Pin) 
Next 
+0

這與我正在使用的數據完全一致,但添加後它似乎有一個流浪的圖釘在我的地圖的中心沒有固定點? – Gaudreau95

+0

檢查您的其他代碼。您可能在某處添加另一個圖釘。可能在XAML中? – rbrundritt

+0

我添加了一個單獨的圖釘的唯一的其他地方是在XAML代碼中,我刪除了這個問題是否會繼續下去。只有在添加您感興趣的代碼片段時纔會發生。 – Gaudreau95