From 9363b0727a21bf295c2aafe9377344edb0162f58 Mon Sep 17 00:00:00 2001 From: "d.breimaier" Date: Wed, 12 Oct 2022 08:09:19 +0200 Subject: [PATCH] Erweiterung GoogleAPI --- VERAG_PROG_ALLGEMEIN/Google/cGoogleAPI.vb | 72 ++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/VERAG_PROG_ALLGEMEIN/Google/cGoogleAPI.vb b/VERAG_PROG_ALLGEMEIN/Google/cGoogleAPI.vb index 4228aa0a..618abe18 100644 --- a/VERAG_PROG_ALLGEMEIN/Google/cGoogleAPI.vb +++ b/VERAG_PROG_ALLGEMEIN/Google/cGoogleAPI.vb @@ -2,6 +2,7 @@ Imports System.Net Imports System.Web Imports System.Text +Imports VERAG_PROG_ALLGEMEIN.DSFinVKService Public Class cGoogleAPI @@ -18,7 +19,7 @@ Public Class cGoogleAPI MsgBox(distance) End Sub - Public Shared Sub GoogleDistance(origin As String, destination As String, ByRef duration As Object, ByRef distance As Object, Optional lkw As Boolean = True) + Public Shared Sub GoogleDistance(origin As String, destination As String, ByRef duration As Object, ByRef distance As Object, Optional lkw As Boolean = True, Optional getValues As Boolean = False) Try Dim url As String = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & HttpUtility.UrlEncode(origin) & "&destinations=" + HttpUtility.UrlEncode(destination) & "&key=" & APIKEY_distancematrix @@ -29,6 +30,58 @@ Public Class cGoogleAPI Dim dsResult As DataSet = New DataSet() dsResult.ReadXml(reader) + Dim textOrValue As String + If getValues Then + textOrValue = "value" + Else + textOrValue = "text" + End If + + If lkw Then + Dim durationSek As Integer = 0 + If dsResult.Tables("duration") Is Nothing Then + durationSek = 0 + Else + durationSek = dsResult.Tables("duration").Rows(0)("value").ToString() + End If + If IsNumeric(durationSek) Then + durationSek = durationSek * 1.5 ' Bei LKW wird die Zeit um diesen Faktor hochgerechnet + Dim iSpan As TimeSpan = TimeSpan.FromSeconds(durationSek) + duration = iSpan.Hours.ToString.PadLeft(2, "0"c) & " Stunden " & iSpan.Minutes.ToString.PadLeft(2, "0"c) & " Minuten" + End If + Else + If dsResult.Tables("duration") Is Nothing Then + duration = "" + Else + duration = dsResult.Tables("duration").Rows(0)(textOrValue).ToString() + End If + End If + + + If dsResult.Tables("distance") Is Nothing Then + distance = "" + Else + distance = dsResult.Tables("distance").Rows(0)(textOrValue).ToString() + End If + + + Catch ex As Exception + MsgBox(ex.Message & ex.StackTrace) + End Try + End Sub + + + Public Shared Sub GoogleRoute(origin As String, destination As String, ByRef duration As Object, ByRef distance As Object, Optional lkw As Boolean = True) + Try + 'die Direction-API bietet detailierte Ergebnisse der Routen + Dim url As String = "https://maps.googleapis.com/maps/api/directions/xml?origin=" & HttpUtility.UrlEncode(origin) & "&destination=" + HttpUtility.UrlEncode(destination) & "&key=" & APIKEY_distancematrix & "&libraries=geometry" + ' MsgBox(url) + Dim request As WebRequest = WebRequest.Create(url) + Dim response As WebResponse = CType(request.GetResponse(), HttpWebResponse) + Dim reader As StreamReader = New StreamReader(response.GetResponseStream(), Encoding.UTF8) + Dim dsResult As DataSet = New DataSet() + dsResult.ReadXml(reader) + If lkw Then Dim durationSek As Integer = 0 If dsResult.Tables("duration") Is Nothing Then @@ -56,9 +109,26 @@ Public Class cGoogleAPI distance = dsResult.Tables("distance").Rows(0)("text").ToString() End If + Dim distanceEU = 0 + Dim distanceNotEU = 0 + + + + For Each Row As DataRow In dsResult.Tables(0).Rows + For Each Coll As DataColumn In dsResult.Tables(0).Columns + Dim s As String = Row(Coll.ColumnName).ToString() + Next + Next + + + + + Catch ex As Exception MsgBox(ex.Message & ex.StackTrace) End Try End Sub + + End Class