Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
Bing Maps WPF control - update PushPin location using events on different thread

Answered Bing Maps WPF control - update PushPin location using events on different thread

  • Saturday, February 04, 2012 4:33 PM
     
     

    I am creating an application using the Bing Mpas WPF control that needs to display a variable number of Pushpins. The number and identity of the Pushpins varyover time (data from a database or binding) and the location of each pushpin needs to be adjusted using information coming from a number of GPS streams running in a separate (background) scanning thread.

    The changes in GPS data generate location update events, and I need the Pushpins to move accordingly. Unfortunately I cannot seem to get around the problem of cross-threading errors. I am using the MVVM design model. Any suggestions?

All Replies

  • Monday, February 13, 2012 8:48 PM
     
     Answered

    Try this:

    ...

    this.MyMap.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,

    newAction( delegate()

    {

    Pushpinpin = newPushpin();

                    pin.Location =

    newLocation( latitude, longitude );

                    pin.ToolTip = incident.Text511;

    this.MyMap.Children.Add( pin );

                  }

              ) );

  • Wednesday, February 15, 2012 8:12 AM
     
     

    Thanks steve - I have now used a slight variant of your suggestion, using the Dispatcher, and it works fine.

    I now have multiple pushpins jumping all over the map in real time, just as planned!


    Sleepwalker