(VB.NET (4.0)) Easy way to add markers (Form)

Aug 26, 2010 at 9:30 PM
Edited Aug 26, 2010 at 9:31 PM

Ola,

I have a list of addresses (over 2000) in a combobox. Each time I change the value of the combobox a new CurrentPosition = New PointLatLng(... , ...) is set. The map "navigates" to the correponding PontLatLng perfectly. Now I want to add a marker to the addresses. I found a way to add markers using the overlay, but I need 7 lines of code for each address.

Private Layer_Markers As GMapOverlay
Private CurrentMarker As GMapMarker
Private TempPoint As PointLatLng
Private TempMarker As GMapMarker

Private Sub load_map()
    TempPoint = New PointLatLng(53.219514, 5.483869)
    TempMarker = New GMapMarkerGoogleGreen(TempPoint)
    Layer_Markers = New GMapOverlay(map, "Layer_One")

    Layer_Markers.Markers.Add(TempMarker)
    map.Overlays.Add(Layer_Markers)
    CurrentMarker = TempMarker
    map.ZoomAndCenterMarkers("Layer_One")

I use the Combobox-SelectedIndexChanged_event to set the PointLatLng

Select Case myCombobox.Text
    Case "blabla"
       gMap.CurrentPosition = New PointLatLng(..., ...)
    Case "more_blabla"
       gMap.CurrentPosition = New PointLatLng(..., ...)
    .... etc (for more then 2000 times

I guess you can understand that I don't want to add all the lines on every "Case". So I was wondering if there was a quicker way or perhaps that could be implemented:

something simple like:

gMap.CurrentPosition = New PointLatLng(..., ...)
gMap.Markers.Add(gMap.CurrentPosition) ' one line only to add the marker

Thanks for the help in advance.

Aug 26, 2010 at 10:08 PM

create a function, use it ;}

Aug 27, 2010 at 6:53 AM

Good point there. Didn't think of it. But wondering if it's possible to implement it in the dll.

Aug 27, 2010 at 8:07 AM

yes but i need to know how it looks, and you can easily create extension method, so it looks that function is 'inside' dll, later i can put it there really

Aug 27, 2010 at 8:25 AM
Private Sub PlaatsMarker(ByVal myPos As Windows.Point)
        myMarker = New GMap.NET.WindowsPresentation.GMapMarker(GMapControl1.FromLocalToLatLng(CInt(myPos.X), CInt(myPos.Y)))
        Dim myMemoryStream As MemoryStream = New MemoryStream
        Dim strFile As String = strGraphicsPath & "Down_16.png"
        Dim myFileStream As FileStream = New FileStream(strFile, FileMode.Open, FileAccess.Read)
        myMemoryStream.SetLength(myFileStream.Length)
        myFileStream.Read(myMemoryStream.GetBuffer(), 0, CInt(myFileStream.Length))
        Dim mySource As BitmapImage = New BitmapImage()
        myMemoryStream.Flush()
        myFileStream.Close()
        mySource.BeginInit()
        mySource.StreamSource = myMemoryStream
        mySource.EndInit()
        Dim myImage As New Image
        myImage.Source = mySource
        myImage.Stretch = Stretch.None
        Dim myOffsetX As Double = Math.Round(mySource.Width)
        Dim myOffSetY As Double = Math.Round(mySource.Height)

        myMarker.Offset = New System.Windows.Point(-myOffsetX, -myOffSetY)
        myMarker.ForceUpdateLocalPosition(GMapControl1)
        myMarker.Shape = myImage
        GMapControl1.Markers.Add(myMarker)

    End Sub
 
Aug 27, 2010 at 8:39 AM

hm.. are you using old version ForceUpdateLocalPosition is internal now, no need to call

Aug 27, 2010 at 8:53 AM

Radioman,

Yes, i use older verion (1.4.92). In newer version my polygons doesn't work any more. (WPF)

We had a discussion about this before. But i couldn't resolve this. So i still use older version.

But the code i gave works quick and fine.

 

Heru

Aug 27, 2010 at 8:55 AM

hm..

Aug 27, 2010 at 9:24 AM
Edited Aug 27, 2010 at 10:07 AM

Thanks Heru. First need to try to understand your code. Seems there is a lot I don't need to add the marker.

EDIT: Won't work, 'cause I need to work with "overlay". But mucho thanks for thinking with me.