<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<!--Created: 8/7/2015 10:59:44 AM-->
<!--ACTOptimumVersion: 6.0.5668.17490-->
<AutoDataItems ACTOptimumVersion="6.0.5668.17490" Created="8/7/2015 10:59:44 AM">
    <AutoDataControl Created="8/7/2015 10:59:44 AM" ClassName="Melville_Schellmann.ACTOptimum3.Control.AutoData3.AutoData3" PrefClassVersion="1.0" ACTOptimumVersion="6.0.5668.17490">
        <Source>' #ScriptName: GeoCode2
    ' #Description: Verifies the complete address through a Google service based on partial address information in an Act! -record. In addition, the geographical coordinates can be captured into existing Act! -Fields.
    ' #Copyright: © 2011-2018 by Melville-Schellmann
    ' #Author: Robert Schellmann, rs@melville-schellmann.de
    ' #Version: 2.5 (09.06.2020) Correct URL encoding with characters like #
    ' #Version: 2.4 (28.08.2018) Verwendung einer Browser kompatiblen UserAgent-Kennung
    ' #Version: 2.3 (12.01.2018) Verwendet HTTP-Proxy mit angemeldetem Windows-Benutzer, wenn einer konfiguriert ist.
    ' #Version: 2.2 (16.03.2017) Das Firmen-Feld optional für die Suchbegriffe hinzugefügt
    ' #Version: 2.1 (26.05.2016) Automatischer Suchaufruf als Option. Möglichkeit einen Google Maps API Developer Key zu hinterlegen.
    ' #Version: 2.0 (24.05.2016) Überarbeitung des Adressauswahlfensters mit editierbarem Suchtext.
    ' #Version: 1.5 (04.09.2015) Abfangen von Serverfehlern bei Google Maps
    ' #Version: 1.3 (06.08.2015) Liste mit Ländernamen, wo zuerst die Hausnummer und dann der Straßenname folgt.
    ' #Version: 1.4 (06.08.2015) Wenn Admin Level 1 leer ist, wird Admin Level 2 als Bundesland verwendet.
    ' #Version: 1.2 (25.03.2014) Korrektur der Referencen auf System.Windows.Forms
    ' #Version: 1.1 (13.04.2011) Optional Nutzung eines separaten Feldes für die Straßennummer
    ' #Version: 1.0 (22.03.2011) Erste Version

    'ACTApp.Cursor = Cursors.WaitCursor
    'ACTApp.ExecuteCommand("act-ui://com.act/application/menu/view/refresh")
    'System.Windows.Forms.Application.DoEvents()
    'ACTApp.Cursor = Cursors.Default
    
    ' The following field names between the quotation marks must be adapted to the particular database 
    ' or the fields must be created in the database. A field for the street number must
    ' not necessarily be indicated.

    Dim sFieldNameStreet As String = "Address 1"
    Dim sFieldNameStreetNumber As String = ""
    Dim sFieldNameZIP As String = "ZIP Code"
    Dim sFieldNameCity As String = "City"
    Dim sFieldNameCounty As String = "County"
    Dim sFieldNameCountry As String = "Country"

    ' The company field will only be used as an additional search term, you can leave it blank ("").
    Dim sFieldNameCompany As String = "Company"

    ' When you want to save the geographical coordinates in ACT!, 
    ' enter the field names for the values. It should be Decimal fields 
    ' with 12 digits before the Decimal point and 6 Decimal places.

    Dim sFieldNameCoordinateLongitude As String = ""  ' e.g. "degree of longitude"
    Dim sFieldNameCoordinateLatidude As String = ""   ' e.g. "degree of latitude"

    ' Here you can specify the default value for the "country" box.

    Dim sDefaultCountry As String = "United Kingdom"

    ' Here you can enter your Google-API-Key.
    
    m_sGoogleAPIKey = ""
    
    ' The API-Key must be activeated for the following Google APIs:
    '  - GeoCoding API
    '  - Maps Static API
    ' For more information see: https://console.developers.google.com

    m_sCountriesWithNumberFirstFormat = "Vereinigte Staaten,Vereinigte Staaten von Amerika,USA,US,U.S.A.,U.S.,Vereinigtes Königreich,Irland,United States Of America,United States,United Kingdom,Ireland"
    m_sScriptName = "GeoCode2"
    m_oAutoData = AutoData
    m_lAutoSearchIntervall = 0 'ms

    '#################################################################### from here please do not make changes

    Dim sStreet As String = AutoData.getFieldValue(sFieldNameStreet)
    Dim sStreetNumber As String
    If sFieldNameStreetNumber &lt;&gt; String.Empty Then
      sStreetNumber = AutoData.getFieldValue(sFieldNameStreetNumber)
    Else
      sStreetNumber = String.Empty
    End If
    Dim sZIP As String = AutoData.getFieldValue(sFieldNameZIP)
    Dim sCity As String = AutoData.getFieldValue(sFieldNameCity)
    Dim sCounty As String = AutoData.getFieldValue(sFieldNameCounty)
    Dim sCountry As String = AutoData.getFieldValue(sFieldNameCountry)
    
    Dim sCompany As String = AutoData.getFieldValue(sFieldNameCompany)
    
    Dim colAddresses As System.Collections.Generic.List(Of Address)
    Dim oAddress As Address
    Dim sURL As String
    Dim sSearchText As String
    
    sURL = RenderURL(sStreet, sStreetNumber, sZIP, sCity, IIf(sCountry = String.Empty, sDefaultCountry, sCountry).ToString, sCompany)
    sSearchText = RenderSearchString(sStreet, sStreetNumber, sZIP, sCity, IIf(sCountry = String.Empty, sDefaultCountry, sCountry).ToString, sCompany)
    
    CreateForm(sSearchText)
 
    colAddresses = GetAddresses(sURL)
    InitAddressList(colAddresses)
    
    If m_frmSelection.ShowDialog(ACTApp) = System.Windows.Forms.DialogResult.OK Then
      If m_lstSelection.SelectedItem Is Nothing Then
        GoTo Abbruch
      End If
      oAddress = CType(m_lstSelection.SelectedItem, Address)
      With oAddress
        If sFieldNameStreetNumber = String.Empty Then
          If IsNumberFirstCountry(.Country) Then
            SaveChanges(AutoData, sFieldNameStreet, sStreet, (.StreetNumber &amp; " " &amp; .Street ).Trim)
          Else
            SaveChanges(AutoData, sFieldNameStreet, sStreet, (.Street &amp; " " &amp; .StreetNumber).Trim)
          End If
        Else
          SaveChanges(AutoData, sFieldNameStreet, sStreet, .Street)
          SaveChanges(AutoData, sFieldNameStreetNumber, sStreetNumber, .StreetNumber)
        End If
        SaveChanges(AutoData, sFieldNameZIP, sZIP, .ZIP)
        SaveChanges(AutoData, sFieldNameCity, sCity, .City)
        SaveChanges(AutoData, sFieldNameCounty, sCounty, .County)
        SaveChanges(AutoData, sFieldNameCountry, sCountry, .Country)
        If sFieldNameCoordinateLatidude &lt;&gt; String.Empty Then
          AutoData.setFieldValue(sFieldNameCoordinateLatidude, .LocationLat.ToString)
        End If
        If sFieldNameCoordinateLongitude &lt;&gt; String.Empty Then
          AutoData.setFieldValue(sFieldNameCoordinateLongitude, .LocationLng.ToString)
        End If
      End With
    End If

    Abbruch:
    Return String.Empty

  End Function
  
  Private Shared m_sScriptName As String
  Private Shared m_oAutoData As Melville_Schellmann.ACTOptimum3.Control.AutoData3.AutoDataScript
  Private Shared m_sGoogleAPIKey As String
  Private Shared m_lAutoSearchIntervall As Integer
  Private Shared m_frmSelection As System.Windows.Forms.Form
  Private Shared m_txbSearchText As System.Windows.Forms.TextBox
  Private Shared m_lstSelection As System.Windows.Forms.ListBox
  Private Shared m_splVertical As System.Windows.Forms.Splitter
  Private Shared m_picImage As System.Windows.Forms.PictureBox
  Private Shared m_btnOK As System.Windows.Forms.Button
  Private Shared m_oTimer As System.Windows.Forms.Timer
  Private Shared m_oToolTip As System.Windows.Forms.ToolTip
  
  
  #Region "Is Country with number before the street name in address"
  
  Private Shared  m_sCountriesWithNumberFirstFormat As String 
  
  Private Shared Function IsNumberFirstCountry(sCountryName As String) As Boolean
    Return IsStringInList(sCountryName, m_sCountriesWithNumberFirstFormat)
  End Function
  
  Private Shared Function IsStringInList(sValue As String, sList As String) As Boolean
    Dim i As Integer
    Dim aValue() As String
    If String.IsNullOrEmpty(sValue) Then
      Return False
    End If
    If String.IsNullOrEmpty(sList) Then
      Return False
    End If
    aValue = sList.Split(New Char() {","c}, System.StringSplitOptions.RemoveEmptyEntries)
    For i = 0 To aValue.Length - 1
      If String.Compare(aValue(i), sValue, True) = 0 Then
        Return True
      End If
    Next
    Return False
  End Function
  #End Region
  
  Private Shared Sub CreateForm(SearchText As String)
    
    m_frmSelection = New System.Windows.Forms.Form
    m_txbSearchText = New System.Windows.Forms.TextBox
    m_lstSelection = New System.Windows.Forms.ListBox
    m_splVertical = New system.Windows.Forms.Splitter
    m_picImage = New System.Windows.Forms.PictureBox
    m_btnOK = New System.Windows.Forms.Button
    m_oTimer = New System.Windows.Forms.Timer
    m_oToolTip = New System.Windows.Forms.ToolTip
    
    
    m_lstSelection.Name = "lstSelection"
    m_lstSelection.SelectionMode = SelectionMode.One
    m_lstSelection.Dock = DockStyle.Left
    m_lstSelection.Width = 320
    m_lstSelection.TabIndex = 0

    AddHandler m_lstSelection.SelectedIndexChanged, AddressOf lstSelection_SelectedIndexChanged
    AddHandler m_lstSelection.DoubleClick, AddressOf lstSelection_DoubleClick

    m_splVertical.Name = "splVertical"
    m_splVertical.Dock = DockStyle.Left
    m_splVertical.Location = New System.Drawing.Point(m_lstSelection.Width, 0)
    m_splVertical.Size = New System.Drawing.Size(3, 100)
    m_splVertical.TabStop = False
    m_splVertical.TabIndex = 1
    AddHandler m_splVertical.SplitterMoved, AddressOf splVertical_Moved
    
    m_picImage.Name = "picImage"
    m_picImage.Dock = DockStyle.Fill
    m_picImage.TabIndex = 2
    AddHandler m_picImage.MouseClick, AddressOf picImage_MouseClick

    m_btnOK.Name = "btnOK"
    m_btnOK.Text = "OK"
    m_btnOK.Dock = DockStyle.Bottom
    m_btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
    m_btnOK.TabIndex = 3

    m_txbSearchText.Name = "txbSearchText"
    m_txbSearchText.Dock = System.Windows.Forms.DockStyle.Top
    m_txbSearchText.Text = SearchText
    m_txbSearchText.TabIndex = 4
    AddHandler m_txbSearchText.TextChanged, AddressOf txbSearch_TextChanged
    AddHandler m_txbSearchText.GotFocus, AddressOf txbSearch_TextGotFocus
    AddHandler m_txbSearchText.LostFocus, AddressOf txbSearch_TextLostFocus

    m_oTimer.Enabled = False
    m_oTimer.Interval = 500
    If m_lAutoSearchIntervall &gt; 0 Then
      m_oTimer.Interval = 100 + m_lAutoSearchIntervall
    End If
    AddHandler m_oTimer.Tick, AddressOf oTimer_Tick
    
    m_frmSelection.SuspendLayout()

    m_frmSelection.Name = "frmSelection"
    m_frmSelection.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    m_frmSelection.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    m_frmSelection.Width = 840
    m_frmSelection.Height = 500 + m_btnOK.Height + m_txbSearchText.Height '562

    m_frmSelection.MinimumSize = New System.Drawing.Size(600, 400)
    m_frmSelection.MaximumSize = New System.Drawing.Size(1024, 800)
    m_frmSelection.MinimizeBox = False
    m_frmSelection.MaximizeBox = False
    m_frmSelection.StartPosition = FormStartPosition.CenterParent
    m_frmSelection.Text = "Address selection"

    m_frmSelection.Controls.Add(m_splVertical)
    m_frmSelection.Controls.Add(m_picImage)
    m_frmSelection.Controls.Add(m_lstSelection)
    m_frmSelection.Controls.Add(m_txbSearchText)
    m_frmSelection.Controls.Add(m_btnOK)
  
    m_frmSelection.AcceptButton = m_btnOK
    m_frmSelection.KeyPreview = True
    AddHandler m_frmSelection.KeyUp, AddressOf frmSelection_KeyUp
    AddHandler m_frmSelection.ResizeEnd, AddressOf frmSelection_ReszieEnd

    m_frmSelection.ResumeLayout()
  End Sub
  
  #Region "Control Events"
  Private Shared Sub frmSelection_ReszieEnd(ByVal sender As Object, ByVal e As System.EventArgs)
    m_frmSelection.Cursor = Cursors.WaitCursor
    If m_lstSelection.Items Is Nothing OrElse m_lstSelection.Items.Count = 0 Then
      ShowNoDataText
    Else
      LoadImageToPicturebox(m_picImage, GetMapURL(m_lstSelection))      
    End If
    m_frmSelection.Cursor = Cursors.Default
  End Sub
  Private Shared Sub splVertical_Moved(ByVal sender As System.Object, ByVal e As System.Windows.Forms.SplitterEventArgs)
    m_frmSelection.Cursor = Cursors.WaitCursor
    If m_lstSelection.Items Is Nothing OrElse m_lstSelection.Items.Count = 0 Then
      ShowNoDataText
    Else
      LoadImageToPicturebox(m_picImage, GetMapURL(m_lstSelection))      
    End If
    m_frmSelection.Cursor = Cursors.Default
  End Sub
  Private Shared Sub txbSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    If m_lAutoSearchIntervall &gt; 0 Then
      If m_oTimer.Enabled = False Then
        m_oTimer.Enabled = True
      End If
      ' Reset timer, begin wait interval again
      m_oTimer.Stop
      m_oTimer.Start
    End If
    
  End Sub
  Private Shared Sub txbSearch_TextGotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim sMsgPressEnterToStartTheSearch As String
    sMsgPressEnterToStartTheSearch = "Please press the Enter key to start the search."
    
    m_oToolTip.SetToolTip(sender, sMsgPressEnterToStartTheSearch)
    m_frmSelection.AcceptButton = Nothing
  End Sub
  Private Shared Sub txbSearch_TextLostFocus(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim sMsgPressF2ToEditTheSearchText As String
    sMsgPressF2ToEditTheSearchText = "Please press the F2 key to edit the search text."
    
    m_oToolTip.SetToolTip(sender, sMsgPressF2ToEditTheSearchText)
    m_frmSelection.AcceptButton = m_btnOK
  End Sub
  Private Shared Sub lstSelection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    m_frmSelection.Cursor = Cursors.WaitCursor
    LoadImageToPicturebox(m_picImage, GetMapURL(m_lstSelection))
    m_oToolTip.SetToolTip(m_lstSelection, m_lstSelection.SelectedItem.ToString)
    m_frmSelection.Cursor = Cursors.Default
  End Sub
  Private Shared Sub lstSelection_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim oListbox As System.Windows.Forms.ListBox
    oListbox = CType(sender, System.Windows.Forms.ListBox)

    If Not oListbox.SelectedItem Is Nothing Then
      CType(oListbox.Parent.Controls("btnOK"), System.Windows.Forms.Button).PerformClick()
    End If
  End Sub
  Private Shared Sub picImage_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Dim lZoom As Integer

    If m_lstSelection.Items Is Nothing OrElse m_lstSelection.Items.Count = 0 Then
      GoTo Abbruch
    End If
    If m_picImage.Tag Is Nothing Then
      m_picImage.Tag = 15
    End If
    lZoom = CType(m_picImage.Tag, Integer)
    Select Case e.Button
      Case System.Windows.Forms.MouseButtons.Left
        lZoom += 1
        If lZoom = 18 Then lZoom = 17
      Case System.Windows.Forms.MouseButtons.Right
        lZoom -= 1
        If lZoom = 2 Then lZoom = 3
    End Select
    LoadImageToPicturebox(m_picImage, GetMapURL(m_lstSelection, lZoom))
    m_picImage.Tag = lZoom
    Abbruch:
  End Sub
  Private Shared Sub frmSelection_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    If e.KeyCode = Keys.Escape Then
      CType(sender, System.Windows.Forms.Form).Close()
    End If
    If e.KeyCode = keys.F2 Then 
      m_txbSearchText.Focus
    End If
    If e.KeyCode = Keys.Down And m_txbSearchText.Focused Then
      m_lstSelection.Focus
    End If
    If e.KeyCode = Keys.Up And m_lstSelection.Focused And m_lstSelection.SelectedIndex = 0 Then
      m_txbSearchText.Focus
    End If
    
    If e.KeyCode = keys.Enter And m_txbSearchText.Focused Then
      oTimer_Tick(m_oTimer, Nothing)
    End If

  End Sub
  Private Shared Sub oTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)

    m_oTimer.Stop
    m_oTimer.Enabled = False
    
    m_frmSelection.Cursor = Cursors.WaitCursor
    Dim sURL As String
    Dim colAddresses As System.Collections.Generic.List(Of Address)
    If m_txbSearchText.text.trim.length &gt;= 3 Then
      sURL = RenderURL(m_txbSearchText.Text)
      colAddresses = GetAddresses(sURL)
    Else
      colAddresses = New  System.Collections.Generic.List(Of Address)
    End If
    InitAddressList(colAddresses)
    m_frmSelection.Cursor = Cursors.Default
  End Sub
  #End Region  
  Private Shared Sub InitAddressList(AddressList As System.Collections.Generic.List(Of Address))
    
    m_frmSelection.Cursor = Cursors.WaitCursor
    m_lstSelection.Items.Clear
    If AddressList Is Nothing OrElse AddressList.Count = 0 Then
      m_lstSelection.Items.Clear
      ShowNoDataText
    Else
      m_lstSelection.SuspendLayout
      m_lstSelection.Items.AddRange(AddressList.ToArray)
      m_lstSelection.ResumeLayout
      m_lstSelection.SelectedIndex = 0
    End If
    m_frmSelection.Cursor = Cursors.Default
  End Sub
  Private Shared Sub SaveChanges(ByVal AutoData As Melville_Schellmann.ACTOptimum3.Control.AutoData3.AutoDataScript, ByVal FieldName As String, ByVal CurrentValue As String, ByVal SelectedValue As String)
    If String.IsNullOrEmpty(SelectedValue) Then
      Exit Sub
    End If
    If CurrentValue = String.Empty Then
      AutoData.setFieldValue(FieldName, SelectedValue)
    Else
      If String.Compare(CurrentValue, SelectedValue, True) &lt;&gt; 0 Then
        If MsgBox(String.Format("Should the field value '{1}' of the field '{0}' be replaced by the new value '{2}'?", _
          FieldName, CurrentValue, SelectedValue), MsgBoxStyle.Question Or MsgBoxStyle.YesNo, m_sScriptName) = MsgBoxResult.Yes Then
          AutoData.setFieldValue(FieldName, SelectedValue)
        End If
      End If
    End If
  End Sub
  Private Shared Sub LoadImageToPicturebox(ByVal oPic As System.Windows.Forms.PictureBox, ByVal URL As String)

    Dim oForm As System.Windows.Forms.Form
    Dim oImageStream As IO.MemoryStream
    Dim oWebClient As Net.WebClient
    Dim aBytes() As Byte
    
    Dim sErrorOccurredWhileProcessingImageData As String
    Dim sErrorOccurredWhileRequestingImageDataFromGoogle As String  
    sErrorOccurredWhileProcessingImageData = "An error occurred while processing the image data."
    sErrorOccurredWhileRequestingImageDataFromGoogle = "An error occurred while requesting the image data from Google."
    
    oForm = CType(oPic.Parent, System.Windows.Forms.Form)
    oForm.Cursor = Cursors.WaitCursor
    Try
      oWebClient = New Net.WebClient()
      aBytes = oWebClient.DownloadData(URL)
    Catch ex As Exception
      ShowText(sErrorOccurredWhileRequestingImageDataFromGoogle &amp; vbcrlf &amp; Replace(ex.Message, ": ", ": " &amp; vbcrlf)) 
      GoTo Abbruch
    End Try
    Try
      oImageStream = New IO.MemoryStream(aBytes)
      oPic.Image = System.Drawing.Image.FromStream(oImageStream)
    Catch ex As Exception
      ShowText(sErrorOccurredWhileProcessingImageData &amp; vbcrlf &amp; ex.Message)
    End Try
    Abbruch:
    oForm.Cursor = Cursors.Default

  End Sub
  Private Shared Function GetMapURL(ByVal oListbox As System.Windows.Forms.ListBox, Optional ByVal Zoom As Integer = -1) As String
    Dim oAddress As Address
    Dim sURL As String = "https://maps.google.com/maps/api/staticmap?size={0}x{1}&amp;maptype=roadmap"
    Dim oNumberFormat As New Globalization.NumberFormatInfo
    Dim sCenter As String = String.Empty
    Dim sColor As String

    Dim lIndex As Integer
    sURL = String.Format(sURL, m_picImage.Width, m_picImage.Height)
    
    oNumberFormat.NumberDecimalSeparator = "."
    For lIndex = 0 To oListbox.Items.Count - 1
      oAddress = CType(oListbox.Items(lIndex), Address)
      If oListbox.SelectedIndex = lIndex Then
        sColor = "red"
        sCenter = String.Format("&amp;center={0},{1}", oAddress.LocationLat.ToString("", oNumberFormat), _
          oAddress.LocationLng.ToString("", oNumberFormat))
      Else
        sColor = "blue"
      End If
      sURL &amp;= String.Format("&amp;markers=color:{0}|label:{1}|{2},{3}", _
        sColor, _
        oAddress.Label, _
        oAddress.LocationLat.ToString("", oNumberFormat), _
        oAddress.LocationLng.ToString("", oNumberFormat))
    Next
    sURL &amp;= "&amp;sensor=false"
    If Zoom &gt; -1 Then
      sURL &amp;= String.Format("&amp;zoom={0}", Zoom)
      sURL &amp;= sCenter
    End If
    
    If Not String.IsNullOrEmpty(m_sGoogleAPIKey) Then
      sURL &amp;= String.Format("&amp;key={0}", m_sGoogleAPIKey)
    End If
    
    Return sURL
  End Function
  Private Shared Function TryGetXPathDocFromURL(URL As String, ByRef oXPDoc As System.Xml.XPath.XPathDocument) As Boolean
    
    ' Proxy Versuch
    Dim oProxy As System.net.IWebProxy
    Dim oUri As System.Uri
    Dim oProxyURI As System.Uri
    Dim oWebRequest As System.net.WebRequest
    Dim oWebResponse As System.Net.WebResponse
    Dim sUserName As String
    Dim sUserPassword As String
    Dim sUserDomain As String
    
    Dim sErrorOccurredWhileGettingAddressDataFromGoogle As String
    
    sErrorOccurredWhileGettingAddressDataFromGoogle = "An error occurred while getting the address data from Google."
    
    TryGetXPathDocFromURL = False
    
    oUri = New System.Uri(URL)
    ' Get current System Proxy
    oProxy = System.Net.HttpWebRequest.GetSystemWebProxy()
    ' Is a Proxy needed for the URL?
    If Not oProxy.IsBypassed(oUri) Then
      oProxyURI = oProxy.GetProxy(oUri)
      oWebRequest = System.Net.WebRequest.Create(oURI)
      
      ' Alternative Proxy login
      '      sUserName = "" ' "mustermann"
      '      sUserPassword = "" ' "1234"
      '      sUserDomain = "" ' "mydomain.local"
      '      oProxy.Credentials = New System.Net.NetworkCredential(sUserName, sUserPassword, sUserDomain)       
      
      ' Use current User credentials
      oProxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials

      oWebRequest.Proxy = oProxy
      Try
        oWebResponse = CType(oWebRequest.GetResponse(), System.Net.WebResponse)
        oXPDoc = New System.Xml.XPath.XPathDocument(New System.Xml.XmlTextReader(oWebResponse.GetResponseStream()), xml.XmlSpace.Default)
      Catch ex As Exception
        MsgBox(sErrorOccurredWhileGettingAddressDataFromGoogle &amp; vbcrlf &amp; ex.Message, MsgBoxStyle.Exclamation, m_sScriptName)
        GoTo Abbruch
      End Try
    Else
      Try
        oWebRequest = System.Net.WebRequest.Create(oURI)
        Dim oHTTPWebRequest As System.Net.HttpWebRequest
        oHTTPWebRequest = CType(oWebRequest, system.net.httpwebrequest)
        If String.IsNullOrEmpty(m_sGoogleAPIKey) Then
          oHTTPWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:37.1) Gecko/20100101 Firefox/37.1" '"Mozilla/5.0 (Windows NT 5.1; rv:44.0) Gecko/20100101 Firefox/44.0"'"Mozilla/5.0 (Windows NT 7.1; rv:37.1) Gecko/20100101 Firefox/37.1"'"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
        Else
          oHTTPWebRequest.UserAgent = "ADB-" &amp; m_sScriptName 
        End If
        oWebResponse = CType(oHTTPWebRequest.GetResponse(), System.Net.WebResponse)
        oXPDoc = New System.Xml.XPath.XPathDocument(New System.Xml.XmlTextReader(oWebResponse.GetResponseStream()), xml.XmlSpace.Default)
        'oXPDoc = New System.Xml.XPath.XPathDocument(URL, Xml.XmlSpace.Default)
      Catch ex As Exception
        MsgBox(sErrorOccurredWhileGettingAddressDataFromGoogle &amp; vbcrlf &amp; ex.Message, MsgBoxStyle.Exclamation, m_sScriptName)
        GoTo Abbruch
      End Try
    End If
    If oXPDoc Is Nothing Then
      MsgBox(sErrorOccurredWhileGettingAddressDataFromGoogle, MsgBoxStyle.Exclamation, m_sScriptName)
      GoTo Abbruch
    End If
    TryGetXPathDocFromURL = True
    
    Abbruch:
    
  End Function
  Private Shared Function GetAddresses(ByVal URL As String) As System.Collections.Generic.List(Of Address)

    Dim oXPDoc As System.Xml.XPath.XPathDocument
    Dim oXPNavigator As System.Xml.XPath.XPathNavigator

    Dim oXPStatus As System.Xml.XPath.XPathNavigator
    Dim oXPResults As System.Xml.XPath.XPathNodeIterator
    Dim oXPResultTypes As System.Xml.XPath.XPathNodeIterator
    Dim oXPAddressComponents As System.Xml.XPath.XPathNodeIterator
    Dim oXPAdrCompTypes As System.Xml.XPath.XPathNodeIterator

    Dim sLabels As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

    Dim lCountAddresses As Integer
    Dim colAddresses As New System.Collections.Generic.List(Of Address)
    Dim oAddress As Address
   
    Dim sErrorOccurredWhileGettingAddressDataFromGoogle As String
    
    sErrorOccurredWhileGettingAddressDataFromGoogle = "An error occurred while getting the address data from Google."

    If TryGetXPathDocFromURL(URL, oXPDoc) = False Then
      GoTo Abbruch
    End If
    Try
      oXPNavigator = oXPDoc.CreateNavigator
    Catch ex As Exception
      MsgBox(sErrorOccurredWhileGettingAddressDataFromGoogle &amp; vbcrlf &amp; ex.Message, MsgBoxStyle.Exclamation, m_sScriptName)
      GoTo Abbruch
    End Try

    oXPStatus = oXPNavigator.SelectSingleNode("/GeocodeResponse/status")
    Select Case oXPStatus.Value
      Case "OK"
        oXPResults = oXPNavigator.Select("/GeocodeResponse/result")
        lCountAddresses = 0
        While oXPResults.MoveNext
          lCountAddresses += 1
          oAddress = New Address
          If lCountAddresses &lt; sLabels.Length Then
            oAddress.Label = sLabels.Chars(lCountAddresses - 1)
          Else
            oAddress.Label = lCountAddresses.ToString
          End If
          oAddress.Formatted = EnsureString(oXPResults.Current.SelectSingleNode("formatted_address").Value)
          oAddress.LocationLat = oXPResults.Current.SelectSingleNode("geometry/location/lat").ValueAsDouble
          oAddress.LocationLng = oXPResults.Current.SelectSingleNode("geometry/location/lng").ValueAsDouble

          oXPResultTypes = oXPResults.Current.Select("type")
          While oXPResultTypes.MoveNext()
            If oAddress.Type &lt;&gt; String.Empty Then
              oAddress.Type &amp;= ";"
            End If
            oAddress.Type &amp;= oXPResultTypes.Current.Value
          End While

          oXPAddressComponents = oXPResults.Current.Select("address_component")
          While oXPAddressComponents.MoveNext
            oXPAdrCompTypes = oXPAddressComponents.Current.Select("type")
            While oXPAdrCompTypes.MoveNext
              'The following code line can be used to display all Google values for testing (remove the ' to activate the code)
              'Msgbox(oXPAdrCompTypes.Current.Value &amp; ": " &amp; EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value))
              Select Case oXPAdrCompTypes.Current.Value
                Case "street_number"
                  oAddress.StreetNumber = EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value)
                Case "route"
                  oAddress.Street = EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value)
                Case "administrative_area_level_1"
                  If Not String.IsNullOrEmpty((EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value))) Then
                    oAddress.County = EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value)
                  End If
                Case "administrative_area_level_2"
                  If String.IsNullOrEmpty(oAddress.County) Then
                    oAddress.County = EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value)
                  End If
                Case "locality","postal_town"
                  If Not String.IsNullOrEmpty((EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value))) Then
                    oAddress.City = EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value)
                  End If
                Case "sublucality"
                Case "country"
                  oAddress.Country = EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value)
                Case "postal_code"
                  oAddress.ZIP = EnsureString(oXPAddressComponents.Current.SelectSingleNode("long_name").Value)
                Case "political"
                'street_number() 
                'route() 
                'administrative_area_level_1() ' Address.County
                'administrative_area_level_2() ' Area 
                'locality() 'Address.City
                'sublucality() '
                'country() ' Address.Country
                'political()
                'postal_code() ' Address.ZIP
              End Select
            End While
          End While
          colAddresses.Add(oAddress)
        End While
      Case "ZERO_RESULTS"
      ' No message
      Case Else
        MsgBox("Response of the Google request: " &amp; oXPStatus.Value, MsgBoxStyle.Exclamation, m_sScriptName)
      ' "OK" means that an error occurred. The address was successfully parsed and one or more geocode was returned.
      ' "ZERO_RESULTS" means that the geo coding was successfully, but no result returned. This can happen, if the geo coding received a not existing address or a latlng at a backwater place.
      ' "OVER_QUERY_LIMIT" means that you have exceeded your quota of queries.
      ' "REQUEST_DENIED" means that your request was rejected, generally caused by a missing sensor parameter.
      ' "INVALID_REQUEST" means... 
    End Select
    Abbruch:
    Return colAddresses
  End Function
  Private Shared Function EnsureString(ByVal Value As Object, Optional ByVal sDefault As String = "") As String

    If Value Is Nothing Then
      Return sDefault
    Else
      Return Value.ToString
    End If

  End Function
  Private Shared Function RenderURL (ByVal sSearchText As String) As String
    Return RenderURL(sSearchText, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty)
  End Function
  Private Shared Function RenderURL(ByVal sStreet As String, ByVal sStreetNumber As String, ByVal sZIP As String, ByVal sCity As String, ByVal sCountry As String, ByVal sCompany As String) As String
    Dim oStringBuilder As New System.Text.StringBuilder
    oStringBuilder.Append("https://maps.google.com/maps/api/geocode/xml?language=en&amp;address=")
    oStringBuilder.Append(ConvertURLFormat((sStreet &amp; " " &amp; sStreetNumber).Trim))
    oStringBuilder.Append(ConvertURLFormat(sZIP))
    oStringBuilder.Append(ConvertURLFormat(sCity))
    oStringBuilder.Append(ConvertURLFormat(sCountry))
    oStringBuilder.Append("&amp;sensor=false")
    If Not String.IsNullOrEmpty(m_sGoogleAPIKey) Then
      oStringBuilder.Append(String.Format("&amp;key={0}", m_sGoogleAPIKey))
    End If
    Return oStringBuilder.ToString
  End Function
  Private Shared Function RenderSearchString(ByVal sStreet As String, ByVal sStreetNumber As String, ByVal sZIP As String, ByVal sCity As String, ByVal sCountry As String, ByVal sCompany As String) As String
    Dim oStringBuilder As New System.Text.StringBuilder
    If Not String.IsNullOrEmpty(sCompany) Then
      oStringBuilder.Append(ConvertSearchFormat("""" + sCompany + """"))
    End If
    oStringBuilder.Append(ConvertSearchFormat((sStreet &amp; " " &amp; sStreetNumber).Trim))
    oStringBuilder.Append(ConvertSearchFormat(sZIP))
    oStringBuilder.Append(ConvertSearchFormat(sCity))
    oStringBuilder.Append(sCountry)

    Return oStringBuilder.ToString
  End Function
  Private Shared Function ConvertSearchFormat(ByVal sValue As String) As String
    Dim sReturnValue As String
    sReturnValue = sValue.Trim
    If sReturnValue &lt;&gt; String.Empty Then
      sReturnValue = sValue.Trim &amp; ", "
    End If
    Return sReturnValue
  End Function
  Private Shared Function ConvertURLFormat(ByVal sValue As String) As String
    Dim sReturnValue As String
    sReturnValue = sValue.Trim
    If sReturnValue &lt;&gt; String.Empty Then
      sReturnValue = Uri.EscapeDataString(sValue.Trim) &amp; ",+"
    End If
    Return sReturnValue
  End Function
  Private Shared Sub ShowNoDataText
    ShowText("Sorry, no data found.")
  End Sub
  Private Shared Sub ShowText(Text As String)
    
    Dim oSadEmoticon As New system.Drawing.Drawing2D.GraphicsPath
    Dim oImage As System.Drawing.Bitmap
    Dim oGraphics As System.Drawing.Graphics
    Dim oFont As System.Drawing.Font
    Dim oPoint As system.Drawing.PointF
    Dim oSize  As system.Drawing.SizeF
    Dim sText As String
    
    sText = Text
    oFont = m_btnOK.Font
    oFont = New system.Drawing.Font(oFont.Name, oFont.Size + 2.0F, oFont.Style, oFont.Unit)
    oImage = New System.Drawing.Bitmap(m_picImage.Width, m_picImage.Height)
    oGraphics = System.Drawing.Graphics.FromImage(oImage)
    oGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
    oSize = oGraphics.MeasureString(sText, oFont)
    oPoint = New System.Drawing.PointF(oImage.Width / 2 - oSize.Width / 2, oImage.Height / 2 - oSize.Height / 2)
    oGraphics.DrawString(sText, oFont, System.Drawing.Brushes.Black, oPoint)
    m_picImage.Image = oImage
    
  End Sub
  
  Class Address
    Public Formatted As String
    Public Street As String
    Public StreetNumber As String
    Public City As String
    Public ZIP As String
    Public County As String
    Public Country As String
    Public LocationLat As Double
    Public LocationLng As Double
    Public Label As String
    Public Type As String

    Public Overrides Function ToString() As String
      Return String.Format("({0}) {1}", Label, Formatted)
    End Function

    Public Sub New()
      Formatted = String.Empty
      Street = String.Empty
      StreetNumber = String.Empty
      City = String.Empty
      ZIP = String.Empty
      County = String.Empty
      Country = String.Empty
      LocationLat = 0.0
      LocationLng = 0.0
      Label = String.Empty
      Type = String.Empty
    End Sub
  End Class
  
  Private Function Dummy() As String
    Return String.Empty</Source>
        <SourceComment>Begriff: {0}</SourceComment>
        <TargetFields></TargetFields>
        <MsgText>{0}</MsgText>
        <Picklist></Picklist>
        <Multiple>False</Multiple>
        <Expandable>True</Expandable>
        <OverwriteAlways>True</OverwriteAlways>
        <CopyToClipboard>False</CopyToClipboard>
        <ShowMsgBox>False</ShowMsgBox>
        <PositionMode>1</PositionMode>
        <FlatStyle>Standard</FlatStyle>
        <AutoDataText>GeoCode</AutoDataText>
        <TextAlign>MiddleCenter</TextAlign>
        <AutoDataFormSize>160, 270</AutoDataFormSize>
        <TooltipText>Validates an address and determine their coordinates.</TooltipText>
        <RefreshLoadedViews>False</RefreshLoadedViews>
    </AutoDataControl>
</AutoDataItems>