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?
- Moved by Richard_BrundrittMicrosoft Employee, Owner Saturday, March 10, 2012 1:23 PM (From:Bing Maps: Map Control and Web services Development)
All Replies
-
Monday, February 13, 2012 8:48 PM
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 );
}
) );
- Marked As Answer by Richard_BrundrittMicrosoft Employee, Owner Wednesday, February 15, 2012 8:55 AM
-
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

