PointLatLon from datatable

Topics: Windows Forms
Jul 27, 2012 at 1:29 PM
Edited Jul 27, 2012 at 1:30 PM

Hi,

my Code:

 

 

Dim lat As String = dtable.Rows(0).Item(3)
Dim lon As String = dtable.Rows(0).Item(4)

Dim m As New GMapMarker_Custom(New PointLatLng(lat, lon))


 

in the Table FIeld

dtable.rows(0).item(3) = 48.333

dtable.rows(1).item(4) = 8.555

 

but the GMapMarker doesnt accept the values and dont appear

 

help pls thx

Jul 27, 2012 at 1:50 PM

Hi,

did you add the marker to an overlay and this overlay to the control?

 

Michael

Jul 27, 2012 at 4:30 PM
Edited Jul 27, 2012 at 4:39 PM

 

Sub MarkersWachen()
        Dim Wachen As New GMap.NET.WindowsForms.GMapOverlay(GMapControl1, "Wachen")
        GMapControl1.Overlays.Add(Wachen)

        Dim conn As New MySqlConnection
        Dim cmd As New MySqlCommand
        Dim da As New MySqlDataAdapter(cmd)
        Dim dtwachen As New DataTable

        conn.ConnectionString = REMOVED
        cmd.Connection = conn
        conn.Open()

        cmd.CommandText = "Select * from gebaeude WHERE GebaeudeTyp_idGebaeudeTyp = '2'"
        da.Fill(dtwachen)

        conn.Close()

        Dim lat As String = dtwachen.Rows(0).Item(3)
        Dim lon As String = dtwachen.Rows(0).Item(4)

        Label1.Text = lat & "  / " & lon
        Dim m As New GMapMarker_Wachen(New PointLatLng(lat, lon))
        m.Size = New Drawing.Size(25, 25)
        m.ToolTipText = dtwachen.Rows(0).Item(1).ToString
        Wachen.Markers.Add(m)


When i put 
Dim lat as string = 49.444
dim lon as strin = 6.888 

it works but not with dtwachen.rows(0).item(3)

and i made sure 48.888 is in there !



Jul 27, 2012 at 6:09 PM

SOLVED !!

Jul 28, 2012 at 11:34 PM

How?

Nov 12, 2014 at 12:23 PM
Can you please tell me how did you solve that?
Nov 12, 2014 at 12:39 PM
Edited Nov 12, 2014 at 12:41 PM
Just missing the double parsing for the Lat, Lon values
        Dim lat As String = dtwachen.Rows(0).Item(3)
        Dim lon As String = dtwachen.Rows(0).Item(4)

        Dim m As New GMapMarker_Wachen(New PointLatLng(CDbl(lat), CDbl(lon)))
Or you can define the variables lat, lon as double from the beginning.
        Dim lat As Double = CDbl(dtwachen.Rows(0).Item(3))
        Dim lon As Double = CDbl(dtwachen.Rows(0).Item(4))

        Dim m As New GMapMarker_Wachen(New PointLatLng(lat, lon))
Nov 12, 2014 at 1:50 PM
Hello

Please note that accessing a datatable as you do is not really a good idea it is much better to access by the name of the column

dtwachen.Rows(0).Item("MyColumn");

Is is also strange the source data is in String

Maybe you can avoid the double conversion by doing this

Dim lat As Double = dtwachen.Rows(0).Item("MyColumn")

This is cSharp like, I assume than VB can do this