开发者

Removing pushpin from Bing map

I do not quite understand why this isnt working: (Bing maps silverlight control WP7)

Add a开发者_Python百科 pushpin here:

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

Remove the pushpin here:

map1.Children.Remove(pushpin1);

This wont remove the pushpin, what am I doing wrong?

Thanks.


I got this to work with the following code:

    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);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜