1
votes

I'm trying to add a PushPin to a map in Windows Phone 8 from code behind. I know how to do this from XAML

<maps:Map x:Name="routeMap">
    <maptk:MapExtensions.Children>
        <maptk:Pushpin GeoCoordinate="22.34, 88.30" Content="My pin" />
    </maptk:MapExtensions.Children>
</maps:Map>

How can I do this from code behind?
Thanks.

2

2 Answers

2
votes

Try this:

MapLayer layer1 = new MapLayer();
Pushpin pushpin1 = new Pushpin();
pushpin1.GeoCoordinate = MyGeoPosition;
pushpin1.Content = "Content";
MapOverlay overlay1 = new MapOverlay();
overlay1.Content = pushpin1;
overlay1.GeoCoordinate = MyGeoPosition;
layer1.Add(overlay1);
myMap.Layers.Add(layer1);

You can create new overlay for each pushpin, add all overlays to a layer, and add the layer to the map element.

2
votes

From MSDN

Pushpin pushpin = new Pushpin();
pushpin.Text = "1";
MapLayer.SetPosition(pushpin, new Location(22.34,88.30));
routeMap.Children.Add(pushpin);