从Bing地图中删除图钉

时间:2011-08-14 09:28:18

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

我不太明白为什么这不起作用:( Bing映射Silverlight控件WP7)

在此处添加图钉:

GeoCoordinate location = new GeoCoordinate();
location.Latitude = 51.5;
location.Longitude = 0;
pushpin1.Location = location;               
map1.Children.Add(pushpin1);

在此处删除图钉:

map1.Children.Remove(pushpin1);

这不会移除图钉,我做错了什么?

感谢。

1 个答案:

答案 0 :(得分:4)

我使用以下代码:

    private void AddPushpinButton_Click(object sender, RoutedEventArgs e)
    {
        GeoCoordinate location = new GeoCoordinate() { Latitude = 51.5, Longitude = 0 };
        Pushpin pushpin1 = new Pushpin() { Location = location, Tag = "FindMeLater" };
        map1.Children.Add(pushpin1);
    }

    private void RemovePushpinButton_Click(object sender, RoutedEventArgs e)
    {
        var pushpin = map1.Children.First(p => (p.GetType() == typeof(Pushpin) && ((Pushpin)p).Tag == "FindMeLater"));
        map1.Children.Remove(pushpin);
    }