Im uses winforms and GMap.NET to find out how to use it.
I have a mouse action on the Gmap controller and when the user clicks on some place on the map, I get the xy coordinates, converting them to latitude and longitude, and then draw a marker on the map. But the marker does not fit in the actual location of the mouse cursor, it looks like the marker has a default location and that it is. I tried to move the mouse to another place, and when I clicked the marker was also created in the wrong place (it was the same as the first marker)
I tried using gmap.Overlays.clear () before getting the coordinates and place the marker, but that didn't help.
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);
}
}
source
share