Reading lat-lng (as double) from mysql-server

Topics: General
Oct 20, 2011 at 2:22 PM

Ola,

I'm reading my coordinates from a table with 3 columns (place - lat- long). Goes perfect, but when I convert the string to double for a marker it goes horribly wrong.

Does anyone know how to do this properly?

Dim gps_place As String =  .SelectedNode.Cells(1).Text
Dim cmd_gps As New MySqlCommand("SELECT `lat`, `long` FROM gps WHERE place = " & "'" & gps_place & "'", conn)
reader = cmd_gps.ExecuteReader
While reader.Read
    Dim strLat As Double = CDbl(reader.Item("lat").ToString)
    MsgBox(strLat.ToString)  ' result: 5237861    should be: 52.37861

    Dim strLong As Double = CDbl(reader.Item("long").ToString)
    MsgBox(strLong.ToString)  ' result: 662722   should be: 6.62722
End While

Thanks in advance

Oct 20, 2011 at 2:58 PM

this is not mysql forum, but anyway you should use:

lat = reader.GetDouble(0);
lng =reader.GetDouble(1);

Oct 20, 2011 at 3:36 PM

Thanks, but unfortunately still giving the result without the "dot".

Oct 20, 2011 at 3:53 PM

GetDouble returns double, it has the point ;}

Oct 20, 2011 at 4:03 PM

Hmmmm... The marker is addd at the upper right corner of the map:

'  row-type lat = varchar = 52.37861
'  row-type long = varchar = 6.62722

While reader.Read
   Dim strLat As Double = reader.GetDouble(0)
   Dim strLong As Double = reader.GetDouble(1)

   Dim overlayOne As New GMapOverlay(map_control, "overlay1")
   Dim map_marker As New GMapMarkerGoogleGreen(New PointLatLng(strLat, strLong))
   overlayOne.Markers.Add(map_marker)

   map_marker.ToolTipMode = MarkerTooltipMode.OnMouseOver
   map_marker.ToolTipText = gps_place
   map_control.Overlays.Add(overlayOne)
   map_control.ZoomAndCenterMarkers(overlayOne.Id)
End While
Oct 21, 2011 at 7:38 AM

Anyone with some experience with this?

Oct 21, 2011 at 11:26 AM
Edited Oct 21, 2011 at 11:28 AM

More info: columns are "varchar"  http://i56.tinypic.com/5nkc8w.png

this is the result with the code: http://i51.tinypic.com/i2oyt3.png

Oct 21, 2011 at 12:06 PM

and why they are varchar? ;/ ..anyway then you need to do:

double t = double.Parse("25.222", CultureInfo.InvariantCulture);

Oct 21, 2011 at 12:45 PM
Edited Oct 21, 2011 at 12:55 PM

Ah. now I see it. I shouldn't use the dot, but the comma. Thanks for the help. Works like a charm.

By the way, the "varchar" was simply a test. What is a better type?

Oct 21, 2011 at 12:57 PM

but it fails on systems where default culture uses dots, so the sure way is to use dots and provide invariant culture

Oct 21, 2011 at 1:19 PM

Thanks. Will use as you told me.