Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing pushpin from Bing map

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

Add a 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.

like image 373
Dan Sewell Avatar asked Nov 23 '25 14:11

Dan Sewell


1 Answers

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);
    }
like image 137
Chris Koenig Avatar answered Nov 25 '25 04:11

Chris Koenig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!