多个图钉Bing映射windows phone 7

时间:2012-05-23 11:05:41

标签: c# windows-phone-7 bing-maps

您好我在地图上显示多个图钉时遇到了一些麻烦。到目前为止,我已尝试添加单个图钉或首先将它们放入MapLayer,然后将maplayer添加到地图中,但我仍然只获得我创建的最后一个图钉。代码示例:

MapLayer layer = new MapLayer();
                Pushpin pin1 = new Pushpin();
                GeoCoordinate geo= new GeoCoordinate();
                geo.Latitude = 45.8074417114258 ;
                geo.Longitude = 15.9677000045776;
                pin1.Location = geo;
                layer.Children.Add(pin1);
                Pushpin pin2 = new Pushpin();
                GeoCoordinate geo1 = new GeoCoordinate();
                geo1.Latitude = 45.9074417114258;
                geo1.Longitude = 15.8677000045776;
                pin1.Location = geo1;
                layer.Children.Add(pin2);

                map1.Children.Add(layer);

3 个答案:

答案 0 :(得分:2)

您提供的示例代码将pin1的位置设置为两次,而不是设置pin2的位置。

pin1.Location = geo1;

应该是

pin2.Location = geo1;

答案 1 :(得分:1)

    Instead of doing this, create no of Pushpin objects  you want...
    and set the location of the pushpin..try this

    Pushpin pushpin1 = new Pushpin();
    pushpin1.Location = new GeoCoordinate(21.7679, 78.8718);

    Pushpin pushpin = new Pushpin();
    pushpin1.Location = new GeoCoordinate(45.8074417114258, 15.8677000045776);

    map1.Children.Add(pushpin1);
    map1.Children.Add(pushpin2);

答案 2 :(得分:0)

试试这个,

Pushpin pin2 = new Pushpin();
GeoCoordinate geo1 = new GeoCoordinate();
geo1.Latitude = 45.9074417114258;
geo1.Longitude = 15.8677000045776;
pin2.Location = geo1;
layer.Children.Add(pin2);