如何在Windows Phone 8.1中的Bing Map上绑定MapIcon

时间:2016-01-27 10:08:31

标签: c# windows-phone-8.1 bing-maps

我在Windows Phone 8.1应用上使用Bing Map。准确地说,在XAML文件中,我写了

<Maps:MapControl x:Name="Map" Loaded="Map_Loaded">
    <Maps:MapItemsControl ItemsSource="{Binding Locations}">
        <Maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <Image Source="Images/arte_icon_label.png"
                       Height="25"
                       Maps:MapControl.Location="{Binding Geopoint}"
                       Maps:MapControl.NormalizedAnchorPoint=".5,.5"/>
            </DataTemplate>
        </Maps:MapItemsControl.ItemTemplate>
    </Maps:MapItemsControl>
</Maps:MapControl>

我想添加许多图片,但我不知道添加主题的代码过程是什么。

你能帮我吗?

1 个答案:

答案 0 :(得分:1)

您想要使用C#代码添加多个MapIcon吗?我从以下post获取此代码段。

private async Task SearchNearbyIncidents(Geopoint location)
{
    IList<Geopoint> geoPoints = await bingMapRestService.GetIncidents(MapUtil.GetBoundingBox(location.Position, 5), ConstantValues.BingMapKey);
    foreach (var geoPoint in geoPoints)
    {
        MapIcon mapIcon = new MapIcon
        {
            Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/TrafficYield.png")),
            Location = geoPoint,
            NormalizedAnchorPoint = new Point(0.5, 0.5),
            Title = "Incidents"
        };
        mapControl.MapElements.Add(mapIcon);
    }
}