I need to update my GMap.NET Markers in C#. I added my markers like below:
GMap.NET.WindowsForms.GMapMarker marker2 =
new GMap.NET.WindowsForms.Markers.GMarkerGoogle(
new GMap.NET.PointLatLng(39.81750, 30.52686),
new Bitmap("hello.png"));
marker2.ToolTipText = "Hello";
marker2.ToolTip.Fill = Brushes.Black;
marker2.ToolTip.Foreground = Brushes.White;
marker2.ToolTip.Stroke = Pens.Black;
markers.Markers.Add(marker2);
gMapControl1.Overlays.Add(markers);
I want to update this marker's position in a timer. How can i change this variable in a timer thread? Do i need to make these markers global variables? Thanks for answers.
You will need to pass the overlay into the timer:
System.Timers.Timer t = new System.Timers.Timer();
GMapOverlay overlay_ = new GMapOverlay();
//do stuff to your overlay
t.Elapsed += (sender, e) => MyElapsedMethod(sender, e, overlay_);
Your overlays are all references so you can simply update the markers and it should update on the map (assuming you have added it to the gmapcontrol):
static void MyElapsedMethod(object sender, System.Timers.ElapsedEventArgs e, GMapOverlay overlay)
{
overlay.Markers[..].Position = new PointLatLng(0,0); //for your new position
}
I have not tested this code, but I have good success doing something similar using a background worker.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.