0

I am currently working on an app where I need to show location pins along with address on the map, but currently, when I zoom in or zoom out, the pin keeps moving and from the look and feel, it's clearly visible that pin is also moving from its original lat-long. My XAML template is as following

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

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

Can someone suggest what I am doing wrong here? Can I improve it in some way? The requirement is such that I need to show location address along with pin.

Duncan Lawler
  • 1,772
  • 8
  • 13
Kinjan Bhavsar
  • 1,439
  • 28
  • 58
  • i had problem with pins "drifting" until i set the AltitudeReferenceSystem to Terrain and Altitude of zero. coordinates from geo location are a different ARS and pins can appear to "float" as you pan the map because of it. – escape-llc Sep 08 '21 at 16:16

1 Answers1

0

For XAML to be attached to the map and move with it, you need to call MapControl.SetLocation on the XAML as shown here: https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi

For simple images like your XAML above, it's recommended to use the MapIcon instead as that will be much higher performance. The page above also shows how to use MapIcon

Duncan Lawler
  • 1,772
  • 8
  • 13