none
showing multiple push-pins on bing map

    Question

  • I want to show multiple push pins on my map right now I have the following code, 

    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();
                        
                        MapLayer.SetPosition(pushpin, new Location( DDataFromDB.dLatitude, DDataFromDB.dLongitude));
                        
                        MyMap.Children.Add(pushpin);
    
    }

    I can see the values in data  but I am unable to draw the push-pins or polygons on the map 


    Saturday, January 25, 2014 8:26 AM

Answers

  • Some things to check;

    • Latitude values are between -90 and 90, Longitude values are between -180 and 180.
    • Latitude and longitude values are doubles or floats and not strings.
    • When adding a polygon to the map you have to create a MapShapeLayer, add that to the Shapes property of the map and then add your polygon to the MapShapeLayer you created.

    http://rbrundritt.wordpress.com

    Monday, February 10, 2014 11:52 AM
  • In the code you provided you never created the shapeLayer. Also, you don't use the MapLayer.SetPosition with polygons or polylines. Instead you have to create a LocationCollection object (list of Locations) and set that as the Locations property of the polygon. If you want to create a polygon out of all your data points you can do something like this:

    MapShapeLayer shapeLayer = new MapShapeLayer();
    MyMap.ShapeLayers.Add(shapeLayer);
    
    var polygon = new MapPolygon();
    polygon.FillColor = Colors.Red;
    
    var locs = new LocationCollection();
    
    foreach (tblUsers item in data)
    {                
        locs.Add(new Location((double)DDataFromDB.dLatitude, (double)DDataFromDB.dLongitude));
    }
    
    polygon.Locations = locs;
    
    shapeLayer.Shapes.Add(polygon);

    http://rbrundritt.wordpress.com

    Tuesday, February 11, 2014 9:37 AM
  • You can show multiple pushpins/polygons but you will need more points. A polygon requires a minimum of 3 points to be valid. Do you have coordinates for a polygon in your data? If not, how do you want to represent a polygon on the map?

    http://rbrundritt.wordpress.com

    Wednesday, February 12, 2014 3:10 PM

All replies

  • Some things to check;

    • Latitude values are between -90 and 90, Longitude values are between -180 and 180.
    • Latitude and longitude values are doubles or floats and not strings.
    • When adding a polygon to the map you have to create a MapShapeLayer, add that to the Shapes property of the map and then add your polygon to the MapShapeLayer you created.

    http://rbrundritt.wordpress.com

    Monday, February 10, 2014 11:52 AM
  •  var polygon = new MapPolygon();
                        polygon.FillColor = Colors.Red;
                        MapLayer.SetPosition(polygon, new Location((double)DDataFromDB.dLatitude, (double)DDataFromDB.dLongitude));
                        MyMap.ShapeLayers.Add(shapeLayer);
                        shapeLayer.Shapes.Add(polygon);

    I am getting exception "System.ArgumentException" in 2nd last line as shapeLayer is null

                       
    Monday, February 10, 2014 8:19 PM
  • In the code you provided you never created the shapeLayer. Also, you don't use the MapLayer.SetPosition with polygons or polylines. Instead you have to create a LocationCollection object (list of Locations) and set that as the Locations property of the polygon. If you want to create a polygon out of all your data points you can do something like this:

    MapShapeLayer shapeLayer = new MapShapeLayer();
    MyMap.ShapeLayers.Add(shapeLayer);
    
    var polygon = new MapPolygon();
    polygon.FillColor = Colors.Red;
    
    var locs = new LocationCollection();
    
    foreach (tblUsers item in data)
    {                
        locs.Add(new Location((double)DDataFromDB.dLatitude, (double)DDataFromDB.dLongitude));
    }
    
    polygon.Locations = locs;
    
    shapeLayer.Shapes.Add(polygon);

    http://rbrundritt.wordpress.com

    Tuesday, February 11, 2014 9:37 AM
  • thanks for the help,the code you have provided me is working but the problem is only i can see a one big polygon that points between two coordinates,but i want to show multiple pushpins / polygon for each coordinate 


    • Edited by Mirza.Sahaib Saturday, February 15, 2014 11:10 AM
    Tuesday, February 11, 2014 6:56 PM
  • You can show multiple pushpins/polygons but you will need more points. A polygon requires a minimum of 3 points to be valid. Do you have coordinates for a polygon in your data? If not, how do you want to represent a polygon on the map?

    http://rbrundritt.wordpress.com

    Wednesday, February 12, 2014 3:10 PM
  •  

    Yes I have values in data, I can see only one polygon on map (I have checked it by zooming too it only shows one big polygon)

    here is the latitude and longitude which I can see in 

      locs.Add(new Location((double)DonorsDataFromDB.donorLatitude, (double)DonorsDataFromDB.donorLongitude));

    Wednesday, February 12, 2014 5:39 PM