c# - GMap.Net marker initially in incorrect position -
i have added marker using gmap lat/long specified. when application starts, marker placed in incorrect position(at center of gmap control) , when zoom, goes specified coordinates. bug in gmap or doing wrong? here code.
gmapoverlay markersoverlay, mo2; gmarkergoogle marker, marker5; gmapoverlay polyoverlay; list<pointlatlng> points; gmaproute gr; graphics g; bool start = true; double move = .0001; //double move = 1; double lt = 73, lg = -180; // double lt = 29, lg = -93; public form1() { allocconsole(); initializecomponent(); try { system.net.iphostentry e = system.net.dns.gethostentry("www.google.com"); } catch { gmap.manager.mode = accessmode.cacheonly; messagebox.show("no internet connection avaible, going cacheonly mode.", "gmap.net - demo.windowsforms", messageboxbuttons.ok, messageboxicon.warning); } gmap.mapprovider = gmapproviders.binghybridmap; gmap.position = new pointlatlng(32, -100); gmap.minzoom = 3; gmap.maxzoom = 15; gmap.zoom = 9; markersoverlay = new gmapoverlay("markers"); mo2 = new gmapoverlay("markers5"); marker5 = new gmarkergoogle(new pointlatlng(lt, lg), gmarkergoogletype.orange_small); g = this.creategraphics(); } private void form1_load(object sender, eventargs e) { gmap.dragbutton = mousebuttons.left; gmap.showcenter = false; points = new list<pointlatlng>(); polyoverlay = new gmapoverlay("polygons"); // gmap.position = new pointlatlng(32.6961334816182, -100.2985095977783); // gmap.minzoom = 0; gmappolygon polygon = new gmappolygon(points, "mypolygon"); polygon.fill = new solidbrush(color.fromargb(50, color.magenta)); // polygon.f polygon.stroke = new pen(color.magenta, 2); } protected void onmousemove(object sender, mouseeventargs e) { // base.onmousemove(e); pointlatlng p = gmap.fromlocaltolatlng(e.x, e.y); mouselatlong.text = convert.tostring(p); // console.writeline(marker.position.lat); } private void submitbutton_click(object sender, eventargs e) { // gmap.position = new pointlatlng(40.6961334816182, -100.2985095977783); marker = new gmarkergoogle(new pointlatlng(double.parse(lattextbox.text), double.parse(longtextbox.text)), new bitmap(@"c:\users\vaib\documents\visual studio 2013\projects\testgmap\testgmap\resources\wpt.png")); // gmarkergoogle marker = new gmarkergoogle(new pointlatlng(-25.966688, 32.580528),flag); mo2.markers.add(marker); gmap.overlays.add(mo2); marker.tooltip = new gmaptooltip(marker); marker.tooltiptext = nametextbox.text; marker.tooltipmode = markertooltipmode.always; // x++; if (start) { gmap.position = new pointlatlng(marker.position.lat, marker.position.lng); start = false; } points.add(new pointlatlng(marker.position.lat, marker.position.lng)); // points.add(new pointlatlng(double.parse(lattextbox.text), double.parse(longtextbox.text))); // gmappolygon polygon = new gmappolygon(points, "mypolygon"); gr = new gmaproute(points, "route"); gr.stroke = new pen(color.magenta, 2); //console.writeline(gr.from + "-->"+gr.to); // polygon.stroke = new pen(color.magenta, 2); polyoverlay.routes.add(gr); gmap.overlays.add(polyoverlay); // m1 = new gmarkergoogle(new pointlatlng(gr.from.value.lat, gr.from.value.lng), //gmarkergoogletype.yellow_small); ga = new gmarkerarrow(new pointlatlng(gr.from.value.lat, gr.from.value.lng)); if (points.count >= 2) ga.bearing = (float)final(gr.from.value.lat, gr.from.value.lng, points[1].lat, points[1].lng); // marker2 = new gmapmarkerimage(new pointlatlng(marker.position.lat, marker.position.lng), markersoverlay.clear(); //m1.rot(180); // m1.onrender(g); // markersoverlay.markers.add(marker2); markersoverlay.markers.add(ga); gmap.overlays.add(markersoverlay); }
the trick first add overlay , marker:
gmapcontrol.overlays.add(markersoverlay); markersoverlay.markers.add(marker);
Comments
Post a Comment