allow only one marker

Topics: Windows Forms
Jun 1, 2012 at 1:58 PM



I’m new to, so sorry if I’m asking the obvious…

Anyway, using doubleclick I put a marker on the map which gives me the coordinates in two textboxes – this works brilliant. However on the next doubleclick I would like to remove that first marker before adding a second one. I can’t manage to get it done. See my code below; Markers.Clear() obviously doesn’t work…

I’m using VB.NET in a winform application (VS2010).

Hope you can help!

Many thanks


Private Sub myMap_DoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles myMap.DoubleClick


       Dim mark As New GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(myMap.FromLocalToLatLng(e.X, e.Y))

       Dim xl As New GMap.NET.PointLatLng

       xl = mark.Position()


       Dim overlayOne As New GMapOverlay(myMap, "OverlayOne")





       TextBox2.Text = (xl.Lat.ToString)

       TextBox3.Text = (xl.Lng.ToString)

End Sub

Jun 1, 2012 at 5:55 PM

myMap.Overlays.Add(overlayOne) // on each click you add the same overlay, you only need to do this once in the form constructor

p.s. clear/add works perfectly, anyway you can reuse the same marker and just change it's position

Jun 3, 2012 at 2:16 PM

thanks Radioman, I hadn't initialized the overlay properly. It's working fine now!