如何将图钉添加到Windows Phone 8.1地图控件?

时间:2014-08-09 19:44:13

标签: xaml windows-phone maps windows-phone-8.1 pushpin

我一直在寻找如何执行此任务的示例,但我还没有找到一个明确的任务。有人可以指出我正确的方向。我迷失了......

修改/更新

我设法按照以下示例添加一些标记: http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=8698&m=8686&ct=29035

但是,正如 MSDN文档所述

  

无法保证显示MapIcon。它可能会隐藏起来   隐藏地图上的其他元素或标签。可选的标题   不保证显示MapIcon。如果你看不到文字,   通过增加的ZoomLevel属性的值来缩小   地图控件。

我需要的东西无论如何都会显示出来,几乎不可能找到一个关于如何执行这个简单任务的简单例子! 我必须说使用最新的地图sdk,而不是之前的8.0。

4 个答案:

答案 0 :(得分:5)

我能够使用以下代码

来完成
   public void AddPushpin(BasicGeoposition location, string text)
        {
            var pin = new Grid()
            {
                Width = 50,
                Height = 50,
                Margin = new Windows.UI.Xaml.Thickness(-12)
            };

            pin.Children.Add(new Ellipse()
            {
                Fill = new SolidColorBrush(Colors.DodgerBlue),
                Stroke = new SolidColorBrush(Colors.White),
                StrokeThickness = 3,
                Width = 50,
                Height = 50
            });

            pin.Children.Add(new TextBlock()
            {
                Text = text,
                FontSize = 12,
                Foreground = new SolidColorBrush(Colors.White),
                HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center,
                VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center
            });

            MapControl.SetLocation(pin, new Geopoint(location));
            Map_MainMap.Children.Add(pin);
        }

答案 1 :(得分:3)

Windows Phone 8.1有2个不同的系统。一个是Silverlight,另一个是Win RT。

private void AddMapIcon()
{
    MapIcon MapIcon1 = new MapIcon();
    MapIcon1.Location = new Geopoint(new BasicGeoposition() { Latitude = 47.620,
     Longitude = -122.349 });
    MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
    MapIcon1.Title = "Space Needle";>>
    MapControl1.MapElements.Add(MapIcon1);
}

这是Win RT版本,因此如果您在Silverlight中使用它,它将无法正常工作。

也许您可以详细说明您的问题和Windows Phone 8.1版本。

答案 2 :(得分:1)

你有什么尝试?

您是否阅读过有关Windows Phone 8.1 for Developers – Maps

的文章

引用文章:

  

另一件已改变的事情是像图钉这样的对象   添加。旧的MapLayer和MapOverlay消失了。现在你只需添加   控件到MapControl.Children集合。

还有good article on MSDN代码示例:

private void AddMapIcon()
{
    MapIcon MapIcon1 = new MapIcon();
    MapIcon1.Location = new Geopoint(new BasicGeoposition() { Latitude = 47.620,
      Longitude = -122.349 });
    MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
    MapIcon1.Title = "Space Needle";
    MapControl1.MapElements.Add(MapIcon1);
}

答案 3 :(得分:1)

我用于地图的Universal Apps版本的XAML显示数据绑定引脚:

命名空间:

xmlns:maps="using:Windows.UI.Xaml.Controls.Maps"

XAML:

<maps:MapControl
     Height="800" Width="480" DesiredPitch="45" Center="{Binding MapCenter, Converter={StaticResource CoordinatesListToGeopointConverter}}">
    <maps:MapItemsControl x:Name="myMap" ItemsSource="{Binding Data.Features}">
        <maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <userControls:CustomPushPin maps:MapControl.Location="{Binding Geometry.Coordinates, Converter={StaticResource CoordinatesListToGeopointConverter}}"
                    Fill="{Binding Properties.Mag, Converter={StaticResource MagnitudeToSolidColorBrushConverter} }"
                    BorderThickness="2"
                    Size="{Binding Properties.Mag, Converter={StaticResource MagnitudeToWidthConverter} }"
                    Magnitude="{Binding Properties.Mag}"
                    TapCommand="{Binding DataContext.PinTappedCommand, ElementName=Hub}" CommandParameter="{Binding }"/>

            </DataTemplate>
        </maps:MapItemsControl.ItemTemplate>
    </maps:MapItemsControl>
    <maps:MapControl.ColorScheme>
        <maps:MapColorScheme >Light</maps:MapColorScheme>
    </maps:MapControl.ColorScheme>
</maps:MapControl>

我使用自定义图钉(对于此应用,它根据绑定的数据而在大小和颜色上有所不同)但它们始终显示在地图上。

我希望这有帮助,如果您需要任何具体细节,请告诉我。

相关问题