Resolved Winform Call to Google API to get full address


Well-known member
Aug 25, 2013
Programming Experience

Im designing a winform app to capture the full address using a ggole API to complete the adresses of CLients being added to the system automatically.

I have the details from Google A Geocoding API request takes the following form:

I have succeeded before using google API to get distance between post codes but am hitting a brick wall here. as the REQUEST_DENIED is all I get back, although I know my key is correct!

Here is my vb code to date, using Newtson.Json and http libraries

I have a simple Form with 3 textboes for the address and 1 button to execute the code
Imports System.IO
Imports System.Net
Imports System.Net.Http
Imports Newtonsoft.Json
Imports System.Text.RegularExpressions

Public Class Form1
    Private API_Key As String = "********************************"
    Private rgx As New Regex("[^a-zA-Z0-9 ]")

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.tbEircode.Text = "****"
    End Sub

    Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim EDate As DateTime

        Dim address = "" ' "" & Me.API_Key.ToString & "&sensor=false"
        ' Dim Eircodes(20) As String 'Array
        ' Dim x, y, z As Integer
                '*****  Check Eircode First ******
                If Me.tbEircode.Text = "" Then
                    MessageBox.Show("No Eircode, please correct")
                    Exit Sub
                End If
                MessageBox.Show(Me.tbEircode.Text & " Eircode sent to Google Maps")
                '***************  Get them in order with | and destination address
                Dim OrgAddress As String = ""
                OrgAddress = Me.tbEircode.Text & ",IRELAND"
               'alt test works OK, but not full address
               'address = "" & Me.API_Key.ToString & "&sensor=false"
                address = "" & OrgAddress & "language=en-EN&key=" & Me.API_Key.ToString
                Using client As New Net.Http.HttpClient(), result = Await client.GetAsync(address)
                    If result.IsSuccessStatusCode Then
                        Dim content = Await result.Content.ReadAsStringAsync
                        Dim response = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Response)(content)
                        Me.tbAddress1.Text = response.status
                        Me.tbAddress2.Text = response.origin_addresses.First 'ToString
                        Me.tbAddress3.Text = response.destination_addresses.First
                        Me.tbAddress1.Text = "error downloading"
                    End If
                End Using
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Google Distance Calculator")

        End Try

    End Sub

    Class GMatrix
        Public Property status As String
        Public Property elements As String
        Public Property rows() As Array
        'Public Property Punchline As String
    End Class

    Class ValuePair
        Public Property value As Integer
        Public Property text As String
    End Class

    Class Element
        Public Property status As String
        Public Property duration As ValuePair
        Public Property distance As ValuePair
    End Class

    Class Row
        Public Property elements As Element()  'Array
    End Class

    Class Response
        Public Property status As String
        Public Property origin_addresses As String() ' Array
        Public Property destination_addresses As String() ' Array
        Public Property rows As Row() 'Array
    End Class

End Class
Did you resolve this? Did you get an example complete? You were able to get the full address with the google api. Can you share?