Search code examples
c#silverlightwindows-phone-7bing-mapspushpin

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.


Solution

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