This project is read-only.

Loading latitude/longitude from db fails

Sep 2, 2009 at 10:11 PM

Hi there,

it's turning me crazy, but i really have no idea why i cant retrieve the latitude/longitude from a sqldatasource:(

I have the values stored in two varchar fields: v_latitude and v_longitude.
In the code behind i have this code:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dv As Data.DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), Data.DataView)
        Dim latitude As New Double
        Dim longitude As New Double
        latitude = CType(dv.Table.Rows(0).Item("v_latitude"), String).ToString
        longitude = CType(dv.Table.Rows(0).Item("v_longitude"), String).ToString
        GoogleMap1.Latitude = latitude
        GoogleMap1.Longitude = longitude

        GoogleMap1.Width = 200
        GoogleMap1.Height = 300
        GoogleMap1.Zoom = 6
End Sub

The problem is: in db the latitude is stored as "52.16045" and the longitude as "5.18555".
If i put a detailview on the page and bind it to the sqldatasource it will show those values as they are.

But; the whole googlemap is grey :(
If i check the pagesource i see that "52.16045" is changed into "5216045"!
Check this:
var GoogleMap1 = new Artem.Web.GoogleMap({"Latitude":5216045,"Longitude":518555,);

So somehow the dot in the latitude and longitude is removed and thus providing wrong values to the googlemap control..
If i hardcode the latitude and longitude in de googlemap they DO work.

Anyone with a suggestion? This problem is giving me a headache.
Thanks in advance




Sep 3, 2009 at 7:27 AM


I'm not a great expert in VB, but shouldn't you cast the values from table columns to Double not to String.
As you can see the Latitude and Longitude properties of the GoogleMap control are of type Double.


Sep 3, 2009 at 8:39 AM


i found out what was causing the problem.
It appears that the coordinates aren't stored the proper way.

They're stored in a varchar field like this: 12.34567, but that way they cannot be used by the control because converting it to a double datatype fails because of the dot.
So i've retrieved them as a string, replaced the dot with a comma so it will make 12,34567: a value that CAN be used by the control :-)

replace(latitude, ".", ",") did the trick.


Sep 3, 2009 at 11:31 AM

If you don't cast thtose values to string but to double, I don't think you will have those localization problems with strings at all :)


Sep 3, 2009 at 3:55 PM
Edited Sep 3, 2009 at 7:29 PM

Nope, i've tried to cast those with convert.todouble(),but that didn't work..
So i'll just have to use the replace function because that's the only working solution i know so far.

I'm not sure if i should start a new message, but i ran into another problem: i cannot loop through markers in my dataview.

Basically i want a map with about 20 different markers; all extracted from a sqldatasource.
I've tried the following VB code, but only one marker (the first one) is displayed.

Looking in the source code, i see in CDATA that the other markers are generated too, but they all have the values of the first row.
What is wrong with my loop in page_load ? I'm quite new to this.

Dim dv As Data.DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), Data.DataView)
Dim drv As Data.DataRowView

For Each drv In dv

Dim marker As New GoogleMarker()
Dim a As New HtmlAnchor
a.HRef = "project.aspx?ID=" & dv.Table.Rows(0).Item("project_id")
a.InnerHtml = dv.Table.Rows(0).Item("project_title").ToString
marker.Latitude = Replace(Left(dv.Table.Rows(0).Item("project_gps"), 8), ".", ",").ToString
marker.Longitude = Replace(Right(dv.Table.Rows(0).Item("project_gps"), 7), ".", ",").ToString


Thanks in advance



Solved: i should have get the results from the datarowview, NOT from the dataview itself..
So this is working: marker.Latitude = Replace(Left(drv("project_gps"), 8), ".", ",").ToString