MilkBottle
MilkBottle

Reputation: 4342

How to dynamically create a few pushpin for bing map

How can I dynamically create a few pushpin which I need to add them to the bing Map. Say, I need 10 pushpin.

Below is the code.

for( int i =0 ; i <=10 ; i++)
{

 Pushpin  pp = new Pushpin();

}

--- Update :

Pushpin[] pp = new Pushpin[intcount];

int PinNbr = 1;

//---- get the items out one by one:


foreach (var c in Cat)                       
{

   if (c.GpsLat != null && c.GpsLon != null)                            
   {                                                       
       //--default fixed location : Lat/Lon

       double KM = CalculateDistance("1.xxxxx", "103.xxxxxx", c.GpsLat, c.GpsLon);

       if ((KM < 2.0)) )
       {

            //--- show the pushpin 

           pp[PinNbr] = new Pushpin();

           pp[PinNbr].Content = c.BizId.ToString() + "," + c.BizName;

           pp[PinNbr].Width = 180;
           pp[PinNbr].Height = 120;

           //-------- All use the same eventHandler 

           pp[PinNbr].MouseLeftButtonUp += new MouseButtonEventHandler(Pushpin_MouseLeftButtonUp);

           map1.Children.Add(pp[PinNbr]);

           PinNbr++;    

      }                            

   }

        //-- using Lat/lon

       map1.Center = new GeoCoordinate(1.2xxxx, 103.3xxx);
       map1.ZoomLevel = 13;

}



//-------- All use the same eventHandler 

Upvotes: 0

Views: 726

Answers (1)

anderZubi
anderZubi

Reputation: 6424

If you are using BingMaps in Windows Phone 7.1, you can do it like this:

    for (int i = 0; i <= 10; i++)
    {
        Pushpin pp = new Pushpin();
        pp.Location = new GeoCoordinate(latitude, longitude);
        pp.Content = //Content for the Pushpin;
        myMap.Children.Add(pp); //myMap is your map control
    }

Upvotes: 1

Related Questions