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

    Question

  • 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?

    Saturday, February 04, 2012 4:33 PM

Answers

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

                  }

              ) );

    Monday, February 13, 2012 8:48 PM

All replies

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

                  }

              ) );

    Monday, February 13, 2012 8:48 PM
  • 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

    Wednesday, February 15, 2012 8:12 AM