Entfernung mit Google bestimmen

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Alexprivat.

    Entfernung mit Google bestimmen

    Hallo Wissende,

    ich benötige mal Hilfe bei der Entfernungsbestimmung mittels Google. Ich habe also diese Web Adresse:

    maps.googleapis.com/maps/api/d…ematrix/xml?origins=12681 Blumberger Damm 151+DE&destinations=13053 Gehrensee Str. 99+DE&mode=driving&language=de-DE&sensor=false

    die als Ergebnis eine XML auswirft. Mein Tellerrand endet aber bei der Möglichkeit diese Adresse mittels Visual Basic ins Netz zu schicken und natürlich auch dabei die entsprechende Antwort zu empfangen. Könntet Ihr mir bitte hilfreich zur Seite stehen? Finde nicht adäquates im Internetz.

    Danke aus der Stadt
    Etwas altes aus meinen VB-Zeiten, also bitte mich nicht zerreissen.

    VB.NET-Quellcode

    1. Private Function GetGoogleXMLResponse(ByVal source As String, ByVal destination As String, ByVal mode As String) As String
    2. Dim wClient As New WebClient
    3. wClient.Encoding = System.Text.Encoding.UTF8
    4. Return wClient.DownloadString( _
    5. String.Format(" http://maps.googleapis.com/maps/api/distancematrix/xml?origins={0}&destinations={1}&mode={2}&language=de-DE&sensor=false", source, destination, mode))
    6. End Function
    7. Private Sub CalculateDistance()
    8. Dim Fortbewegungsmittel As String = APIMode.Item(cmbMittel.SelectedIndex).ToString 'https://developers.google.com/maps/documentation/distance-matrix/intro?hl=de#travel_modes
    9. APIResponce = GetGoogleXMLResponse(tbStart.Text, tbZiel.Text, Fortbewegungsmittel)
    10. Dim doc As New XmlDocument()
    11. doc.LoadXml(APIResponce)
    12. Try
    13. If doc.DocumentElement.SelectSingleNode("/DistanceMatrixResponse/row/element/status").InnerText.ToString().ToUpper() <> "OK" Then
    14. ToolStripStatusLabel1.Text = "Eine Angabe ist falsch, bitte erneut eingeben."
    15. Else
    16. Dim xnList As XmlNodeList = doc.SelectNodes("/DistanceMatrixResponse")
    17. For Each xn As XmlNode In xnList
    18. If xn("status").InnerText.ToString = "OK" Then
    19. tbOrigin.Text = xn("origin_address").InnerText.ToString
    20. tbDestination.Text = xn("destination_address").InnerText.ToString
    21. tbDuration.Text = doc.DocumentElement.SelectSingleNode("/DistanceMatrixResponse/row/element/duration/text").InnerText
    22. tbDistanz.Text = doc.DocumentElement.SelectSingleNode("/DistanceMatrixResponse/row/element/distance/text").InnerText
    23. ToolStripStatusLabel1.Text = "OK"
    24. End If
    25. Next
    26. End If
    27. Catch ex As Exception
    28. End Try
    29. End Sub