Im using winforms and GMap.NET in order to learn how to use it.
I have a mouse click action on the Gmap controller and when the user clicks on some place on the map i'm getting the x y coordinates, converting them to latitude and longtitude and then draw the marker on the map. But the marker is not placed in the real mouse cursor location, it looks like the marker has a default place and that's it. I tried to move the mouse to another place and when I clicked the marker was also created at wrong place (it was the same as the first marker)
I tried to use gmap.Overlays.clear() before getting the coordinates and place the marker but this wasn't helpful.
private void gmap_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
double lat = gmap.FromLocalToLatLng(e.X, e.Y).Lat;
double lng = gmap.FromLocalToLatLng(e.X, e.Y).Lng;
GMapOverlay markerOverlay = new GMapOverlay("markers");
GMarkerGoogle marker = new GMarkerGoogle(new
GMap.NET.PointLatLng(lat, lng),
GMarkerGoogleType.green_pushpin);
markerOverlay.Markers.Add(marker);
gmap.Overlays.Add(markerOverlay);
}
}