c# - GMap marker is placed in wrong position -
im using winforms , gmap.net in order learn how use it.
i have mouse click action on gmap controller , when user clicks on place on map i'm getting x y coordinates, converting them latitude , longtitude , draw marker on map. marker not placed in real mouse cursor location, looks marker has default place , that's it. tried move mouse place , when clicked marker created @ wrong place (it same first marker)
i tried use gmap.overlays.clear() before getting coordinates , place marker 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); } }
add overlay first, add marker. no need operations.
gmap.overlays.add(markeroverlay); markeroverlay.markers.add(marker);
by switching around statements you'll achieve right positioning. guess default position true, guess. overlay has not been "hooked" map , gets marker positioned in beforehand. that's why position off initially.
Comments
Post a Comment