Tutorial: How to add custom markers in VB windows forms

Topics: Windows Forms
Jul 27, 2011 at 11:13 PM

Ok dudes, after some cups of really black coffee, two packs of cigarettes, and some nightmares, i have something to share. its quite simple, but can help to other novices (just like me hehe). Here we go:

First, add some bitmaps to your application Resources. (Go to proyect properties, Resources tab, Add a Resource, Add a existing File)

Next, add this to your project:


    Public Class GMapMarker_Custom
        Inherits GMapMarker

        Dim _image As System.Drawing.Image
        Dim _point As PointLatLng

        Sub New(ByVal iPoint As PointLatLng, ByVal discipline As String)
            _point = iPoint
        End Sub

        Public Overloads Overrides Sub OnRender(ByVal g As Graphics)
            'Dim p As New System.Drawing.Point(_point.Lat, _point.Lng)
            g.DrawImageUnscaled(_image, System.Convert.ToInt32(LocalPosition.X), System.Convert.ToInt32(LocalPosition.Y))
        End Sub

        Public Sub ChangeImage(Type As String)
            Select Case Type
                Case "SedFamVerde"
                    _image = My.Resources.CarFamGreen
                Case "SedFamAmarillo"
                    _image = My.Resources.CarFamYellow
                Case "SedFamRojo"
                    _image = My.Resources.CarFamRed
                Case "SedFamNegro"
                    _image = My.Resources.CarFamBlack
            End Select
            MyBase.Size = New Drawing.Size(_image.Size.Width, _image.Size.Height)
            MyBase.Offset = New Drawing.Point(-(_image.Size.Width / 2), -_image.Size.Height)
        End Sub
    End Class


Now, use in this way:

' Here add a overlay to gmap control, and last, add a marker to overlay

        Dim ArrayMarkers(1) As GMapMarker_Custom

        Layer_Markers = New GMapOverlay(GMapControl, "Layer_One")
        ArrayMarkers(1) = New GMapMarker_Custom(New PointLatLng(10.14, -67.44), "SedFamAmarillo")


' If you want to change the bitmap of the marker, to this

Thats all. Quite simple. I Hope somebody will find this small tutorial useful. Thanks to Radioman for making this possible.

Aug 17, 2011 at 4:13 PM

i am using the following and it works fine too.

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

                    Dim maplat As Double = Latitude
                    Dim maplon As Double = Longitude
                    'Create a marker and add it to the overlay (overlayOne)
                    If (maplat = Nothing Or maplon = Nothing) Then

                        Dim markerone As New GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(New PointLatLng(maplat, maplon))
                        markerone.ToolTipMode = MarkerTooltipMode.OnMouseOver
                        markerone.ToolTipText = "Enter Tooltip text here"

                    End If



this is a bit simplified and in my code some parts belong in different loops, but generally it should work.


Oct 23, 2013 at 11:22 AM
any suggestion on how to add name (1,2,3... or A,B,C.....) to marker ?

i have list of markers and want to have identifier
Aug 27, 2014 at 11:46 AM
Here is a VB.Net Code Sample I am able to add to get my map to show how it works (VS2012)

I use an SQL Query, to get data into a dataset:
            Me.gmapData.HoldInvalidation = True
            'ADD THE MARKERS=========

            For Each row As DataRow In dsData.Tables(0).Rows
                II += 1
                sProviderData = row.Item(0) & ": " & row.Item(2) & " - " & Format(row.Item(3), "c")

                gmapDataOL.Markers.Add(New GMarkerGoogle(New PointLatLng(row.Item("Y"), row.Item("X")), GMarkerGoogleType.red))
                gmapDataOL.Markers(II - 1).ToolTipText = sProviderData ' Acts as a Label to display Data in
                gmapDataOL.Markers(II - 1).ToolTipMode = MarkerTooltipMode.Always 'Shows data Label always visible on the map
                gmapDataOL.Markers(II - 1).IsVisible = True
            Next row

            gmapDataOL.IsVisibile = True
            'REFRESH THE MAP
Thanks RadioMan for this great component!!