hi, i am receieving a repsonse from googles json api that has the formatted_address but i want to extract the city and county from either the formatted_address which is displayed in a label (lblAddress.text) or the JSON file Google gave me.
so for example: Palgrove Road, Pennywell, Sunderland, Tyne and Wear, SR4 8DX, UK.
Street/Village/Town/County/Postcode/Country.(This isn't how google columns the data but is how the formatted address displays and how we piece together an address locally)
so i would like to take Sunderland from that label and insert it into a textbox (txtTown.text) and also Tyne and Wear and put that in a text box too (txtCounty.text). these results differ always so the town could be Middlesbrough and the County could be County Durham etc.
the JSON results are
can someone please try and help me or give me an example code that would be very much apprecated. Thanks
This is how i call in the JSON and extract the "formatted_address"
Dim request As HttpWebRequest = Nothing Dim response As HttpWebResponse = Nothing Dim reader As StreamReader = Nothing Dim json As String = Nothing Dim chars() As Char = txtFirstLine.Text For Each c As Char In chars If IsNumeric(c) Then Try 'Create the web request request = DirectCast(WebRequest.Create("http://maps.googleapis.com/maps/api/geocode/json?address=" + txtFirstLine.Text + txtPC.Text & "&sensor=false"), HttpWebRequest) 'Get response response = DirectCast(request.GetResponse(), HttpWebResponse) 'Get the response stream into a reader reader = New StreamReader(response.GetResponseStream()) json = reader.ReadToEnd() response.Close() TextBox1.Text = json If json.Contains("ZERO_RESULTS") Then lblAddress.Text = "No Address Available" End If If json.Contains("formatted_address") Then 'CurrentAddress.Text = "Address Available"; Dim start As Integer = json.IndexOf("formatted_address") Dim [end] As Integer = json.IndexOf(", UK") Dim AddStart As String = json.Substring(start + 21) Dim EndStart As String = json.Substring([end]) Dim FinalAddress As String = AddStart.Replace(EndStart, "") 'Gives Full Address, One Line lblAddress.Text = FinalAddress End If Catch ex As Exception Dim Message As String = "Error: " & ex.ToString() Finally If (response IsNot Nothing) Then response.Close() End If End Try Return json
Edited 2 Years Ago by cbutler7: mistake