Some basic help for VB programmers

May 23, 2010 at 8:26 PM

A simple form with Gmap and two buttons.  It has taken me all weekend to work out how to remove and add markers from a map.  There's no stopping me now!

TTFN, Dennis.

Imports GMap.NET.WindowsForms
Imports GMap.NET
Imports GMap.NET.WindowsForms.Markers

Public Class MainForm
    Private Layer_Markers As GMapOverlay
    Private CurrentMarker As GMapMarker
    Private TempPoint As PointLatLng
    Private TempMarker As GMapMarker

    Private Sub MainForm_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        TempPoint = New PointLatLng(53.381741, -2.935324)
        TempMarker = New GMapMarkerCross(TempPoint)
        Layer_Markers = New GMapOverlay(MainMap, "Layer_One")

        Layer_Markers.Markers.Add(TempMarker)
        MainMap.Overlays.Add(Layer_Markers)
        CurrentMarker = TempMarker

        MainMap.ZoomAndCenterMarkers("Layer_One")
        MainMap.Zoom = 15
        MainMap.Refresh()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Layer_Markers.Markers.Remove(CurrentMarker)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TempPoint = New PointLatLng(53.382, -2.935)
        TempMarker = New GMapMarkerGoogleGreen(TempPoint)
        Layer_Markers.Markers.Add(TempMarker)
    End Sub
End Class

Coordinator
May 23, 2010 at 9:26 PM

nice, but no need to call MainMap.Refresh()