0

I want to draw multiple push-pins /polygons on Bing map, I have windows 8.1, in my data variable it has 4 values, but it doesn't show anything on map.

foreach (tblUsers item in data)
                {
                    Location location = new Location();
                    // item.dLatitude; item.dLongitude;
                    DDataFromDB.userID = item.nUserId;
                   DDataFromDB.dID = item.nDid;
                    DDataFromDB.dLatitude = item.dLatitude;
                    DDataFromDB.dLongitude = item.dLongitude;
                    DDataFromDB.dDate = item.dtAddDate;
                    DDataFromDB.dStatus = item.strStatus;
                    MapLayer layer0 = new MapLayer();

                    Pushpin pushpin = new Pushpin();
                    pushpin.Text = "1";
                    MapLayer.SetPosition(pushpin, new Location( DDataFromDB.dLatitude, DDataFromDB.dLongitude));
                    Map _map = new Map();
                    _map.Children.Add(pushpin);

}
Mirza Sahaib
  • 137
  • 1
  • 2
  • 11

1 Answers1

0

First off it looks like you are creating a map with every pushpin in a loop. You should only create one map and it should be in the XAML (most of the time) and should look something like this:

<Page
    x:Class="BingMapsIntro_WinRT_CS.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    
    xmlns:m="using:Bing.Maps">    

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">    
        <m:Map Name="MyMap" Credentials="YOUR_BING_MAPS_KEY"/>    
    </Grid>    
</Page>

Then in your code get ride of these two lines of code:

Map _map = new Map();
_map.Children.Add(pushpin);

And add this line of code:

MyMap.Children.Add(pushpin);
rbrundritt
  • 16,570
  • 2
  • 21
  • 46
  • I have added Map _map = new Map(); above the loop but no luck – Mirza Sahaib Jan 31 '14 at 06:30
  • You have to add the Map to the view. Either add it as a child of a Grid or Panel that is rendered in XAML or add the map directly in XAML. Right now all you are doing is creating a Map in memory and never rendering it. – rbrundritt Jan 31 '14 at 10:24
  • MapLayer layer0 = new MapLayer(); Pushpin pushpin = new Pushpin(); MapLayer.SetPosition(pushpin, new Location((double)DDataFromDB.dLatitude, ( double) DDataFromDB.dLongitude)); MyMap.Children.Add(pushpin); – Mirza Sahaib Jan 31 '14 at 18:27