当地图放大或在MapsItemsControl下的UWP中缩小时,自定义图钉移动

时间:2017-06-12 04:26:55

标签: c# uwp bing-maps uwp-maps

我目前正在开发一款应用程序,我需要在地图上显示定位销和地址,但是目前,当我放大或缩小时,针保持移动并且从外观和感觉上看,它清晰可见pin也从原来的lat-long移动。我的XAML模板如下

<DataTemplate x:Key="MapItemTemplate">
        <StackPanel Orientation="Vertical"
                x:Name="pushPin"
                DataContext="{Binding}"
                Tapped="pushPin_Tapped">
            <Border BorderThickness="1" BorderBrush="LightGray">
                <StackPanel x:Name="MapIcon"  
                        Background="White" >
                    <TextBlock Text="{Binding LocationAddress}" 
                               Foreground="Black"  
                               FontWeight="SemiBold" 
                               FontSize="12"
                               Margin="5" 
                               TextWrapping="WrapWholeWords"/>
                </StackPanel>
            </Border>
            <Image Height="30"
                   VerticalAlignment="Top" 
                   maps:MapControl.Location="{Binding LocationGeoCoordinate}" 
                   maps:MapControl.NormalizedAnchorPoint="0.5,0.5"
                   Source="ms-appx:///Images/pushpin.png"/>

        </StackPanel>
    </DataTemplate>

.cs代码

MapControl map = new MapControl();                 map.MapServiceToken =“MyMapServiceToken”;

            MapItemsControl itemsMapControl = new MapItemsControl();
            itemsMapControl.ItemTemplate = this.Resources["MapItemTemplate"] as DataTemplate;

            map.Children.Add(itemsMapControl);
            Grid.SetRow(map, 1);

            mapViewGrid.Children.Add(map);
            var stdMapItemControl = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;
            itemsMapControl.ItemsSource = locationsList;
            await map.TrySetViewAsync(locationsList[0].LocationGeoCoordinate, 15D, 0, 0, MapAnimationKind.Bow);

有人可以在这里建议我做错了吗?我能以某种方式改进它吗?要求是我需要显示位置地址和pin。

1 个答案:

答案 0 :(得分:0)

要将XAML附加到地图并随之移动,您需要在XAML上调用MapControl.SetLocation,如下所示: https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi

对于像上面的XAML这样的简单图像,建议使用MapIcon,因为这样会有更高的性能。上面的页面还显示了如何使用MapIcon