在 Bing 个地图 WPF 上显示多个图钉

Displaying multiple pushpins on Bing Maps WPF

当前,当我加载我的程序时 Bing 地图只会将第一个图钉加载到地图上,对于我的示例,我有 4 个图钉应该在加载应用程序时显示,我会添加什么额外的代码为了使它完成所有四个。

此外,如果你不介意回答,我还有几个问题

我需要为每个位置使用循环吗?

我必须给每个人一个单独的名字吗? (图钉)

我可以 link 访问数据库而不是复制位置吗?

是否可以在单击按钮时隐藏或删除图钉?

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

如果你只是想创建这4个pin,那么你可以使用下面的代码:

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)

或者,如果您的位置数据正在更改,或者您有 array/list 位置信息,您可以循环浏览,创建图钉并将它们添加到地图,如下所示:

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