Image as pushpin on maps - Windows phone 8

后端 未结 1 1028
刺人心
刺人心 2021-01-03 14:25

im trying to add a image to a windows phone 8 map, to serve as a pushpin

i have the following code on my XAML



        
相关标签:
1条回答
  • 2021-01-03 14:46

    Use the Phone.Controls.Toolkit as described here:-

    http://wp.qmatteoq.com/maps-in-windows-phone-8-and-phone-toolkit-a-winning-team-part-1/

    The toolkit can be found at either of

    http://phone.codeplex.com/

    or

    https://www.nuget.org/packages/WPtoolkit

    You can then either add the image directly in your XAML as follows:-

    <maps:Map Loaded="MapControl_Loaded" ZoomLevel="18" Name="MapControl">
       <toolkit:MapExtensions.Children>
           <toolkit:Pushpin x:Name="MyPushpin">
               <toolkit:Pushpin.Template>
                   <ControlTemplate TargetType="toolkit:Pushpin">
                       <StackPanel>
                           <Image Source="/Images/MapScreen/MapScreenCurrentLocationPin.png" Stretch="Uniform" Width="50" Height="50" HorizontalAlignment="Center"/>
                        </StackPanel>
                    </ControlTemplate>
                </toolkit:Pushpin.Template>
            </toolkit:Pushpin>
        </toolkit:MapExtensions.Children>
    </maps:Map>
    

    or you can add it in C# as follows:-

    MapOverlay overlay = new MapOverlay
    {
        GeoCoordinate = myMap.Center,
        Content = new Ellipse
        {
            Fill = new SolidColorBrush(Colors.Red),
            Width = 40,
            Height = 40
         }
    };
    MapLayer layer = new MapLayer();
    layer.Add(overlay);
    
    myMap.Layers.Add(layer);
    

    You should be able to add a Grid with an image instead of an ellipse as shown above.

    Let me know if this worked for you.

    0 讨论(0)
提交回复
热议问题