get Latitude and Longitude of found location

Apr 1, 2010 at 10:19 AM

Hello,

If i use the ucVEarth.VE_FindLocations(locations, True, True, Nothing) function, i want to retrieve the longitude and latitude of the found location.

How can i do this?

I tried to use the following (within VB.NET):

 

    AddHandler ucVEarth.VE_OnFinishedFindingLocations, AddressOf FindLocationsCallBack

AddHandler ucVEarth.VE_OnFinishedFindingLocations, AddressOf FindLocationsCallBack

Private Sub butSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSearch.Click

        Dim strAdres As String = String.Empty

        strAdres = Me.txtStraat.Text + "," + Me.txtPostcode.Text + "," + Me.txtPlaats.Text

        Dim callbackFunction As MethodInvoker

        Try

            Dim locations As New List(Of SearchLocation)()

            Dim a As New SearchLocation()

            a.Where = strAdres

            a.PushPinDescription = strAdres

            a.PushPinLayer = "RoutePlanning"

            a.PushPinTitle = strAdres

            locations.Add(a)

            ucVEarth.VE_FindLocations(locations, True, True, Nothing)

            Me.butRouteToSearchedLocation.Visible = True

        Catch ex As Exception

            MsgBox("fout: " & ex.Message)

        End Try

    End Sub

  Private Sub FindLocationsCallBack()
        Dim locations As New List(Of SearchLocation)()
        For Each loc As SearchLocation In Locations
            Me.txtSearchLat.Text = loc.Latitude
            Me.txtSearchLon.Text = loc.Longitude
        Next
    End Sub
Thanks a lot.
Edward

 

Coordinator
Apr 6, 2010 at 11:42 AM
Edited Apr 6, 2010 at 11:55 AM

Hi there,

can you tell me what goes wrong, do you get an Exception? if so, what is the message?

*edit* found your problem i think.

You define a new list with type SearchLocation  in the button clicked event handler. Then you go searching for the lat/lon of the address. In the callback method you define a new list with type SearchLocation. You should not do that but loop trough the already instantiated list. In order to do that you should make the list al class variable like this:

 

AddHandler ucVEarth.VE_OnFinishedFindingLocations, AddressOf FindLocationsCallBack

Dim locations As New List(Of SearchLocation)()

Private Sub butSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSearch.Click

        Dim strAdres As String = String.Empty

        strAdres = Me.txtStraat.Text + "," + Me.txtPostcode.Text + "," + Me.txtPlaats.Text

        Dim callbackFunction As MethodInvoker

        Try

            Set locations = New List(Of SearchLocation)()

            Dim a As New SearchLocation()

            a.Where = strAdres

            a.PushPinDescription = strAdres

            a.PushPinLayer = "RoutePlanning"

            a.PushPinTitle = strAdres

            locations.Add(a)

            ucVEarth.VE_FindLocations(locations, True, True, Nothing)

            Me.butRouteToSearchedLocation.Visible = True

        Catch ex As Exception

            MsgBox("fout: " & ex.Message)

        End Try

    End Sub

 

  Private Sub FindLocationsCallBack()
         DELETED The line Dim locations As New List(Of SearchLocation)()
         For Each loc As SearchLocation In Locations
            Me.txtSearchLat.Text = loc.Latitude
            Me.txtSearchLon.Text = loc.Longitude
        Next
    End Sub
The idea is that the original list with locations is updated with the information about the lat/lon coordinates...