我試圖在Windows 10應用程序中添加多個圖釘到bing地圖。我面臨的問題是,它只是最後一次添加的經緯度,長時間被添加。讓我後我的代碼:將多個圖釘添加到bing地圖
map.xaml:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Hamburger_Heaven_Challenge"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"
x:Class="Hamburger_Heaven_Challenge.Map"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Maps:MapControl x:Name="MyMap" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="700" Width="1260">
</Maps:MapControl>
</Grid>
map.xaml.cs:
public sealed partial class Map : Page
{
PushPin pushPin = new PushPin();
public Map()
{
this.InitializeComponent();
AddPushPins();
AddIcon();
MyMap.Center = new Geopoint(new BasicGeoposition() {Latitude = 46.8442643, Longitude = 2.5992004 });
MyMap.ZoomLevel = 6;
}
public void AddPushPins()
{
pushPin.AddPushPin(46.8442643, 2.5992004);
pushPin.AddPushPin(48.873121, 2.374912);
}
public void AddIcon()
{
MapIcon myIcon = new MapIcon();
myIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
myIcon.Title = "Apartment here";
MyMap.MapElements.Add(myIcon);
for (int i = 0; i < pushPin.Items().Count; i++)
{
myIcon.Location = pushPin.MyGeopoint(i);
}
}
}
pushpin.cs:
internal class PushPin
{
private ObservableCollection<Geopoint> items;
public PushPin()
{
items = new ObservableCollection<Geopoint>();
}
public void AddPushPin(double latitude, double longitude)
{
items.Add(new Geopoint(new BasicGeoposition() { Latitude = latitude, Longitude = longitude }));
}
public Geopoint MyGeopoint(int i)
{
return items[i];
}
public ObservableCollection<Geopoint> Items()
{
return items;
}
}
我認爲我的問題是我經常重寫mapicon我以前創建,但我如何解決這個問題? 任何點在正確的方向將不勝感激! Ps。我已經嘗試綁定到ObservableCollection
,但我們還沒有足夠的關於數據綁定,我想出來。
我回答了一個相關的問題[有一天](http://stackoverflow.com/questions/33501036/mvvm-add-points-to-a-map/33527056#33527056),它描述瞭如何綁定一個'ObservableCollection'到'Map'控件。如果有幫助。 –
@MikeEason你的答案遠遠超出它的要求。 – MajkeloDev
@MikeEason有沒有更簡單的方法來以編程方式添加它們?而不是必須點擊添加它們。 – Evilunclebill