var results() as variant = ParseJSON( jsonString )
var resultsDict as Dictionary = results( 0 )
var geometry as Dictionary = resultsDict.Value( "geometry" )
var location as Dictionary = geometry.Value( "location" )
var lat as double = location.Value( "lat" )
var lng as double = location.Value( "lng" )
I’m using the code below in Xojo 2020 r2.1.
One still should add some errorhandling and your own Google API key. The one used here is just a (not working) example key.
con = New imUrlConnection
Dim streetNr As String = "790"
Dim street As String = "Bündtenweg"
Dim city As String = "Kleinlützel"
Dim zip As String = "42452"
Dim qry As String = "https://maps.googleapis.com/maps/api/geocode/json?address=" _
+ EncodeURLComponent(streetNr + "+" + street + "," + zip + "+" + city) _
+ "&key=AIzaSyAPoOR_jhakjhIUZhfiuz_dsfT5LaPJcQE"
Var jsonData As String = con.SendSync("GET", qry, 30)
TextArea1.Text = jsonData
Dim jas As New JSONItem
jas.Load(jsonData)
Dim lat,l1 As String
Dim lng,l2 As String
l1 = jas.Child("results").ChildAt(0).Child("geometry").child("location").value("lat")
l2 = jas.Child("results").ChildAt(0).Child("geometry").child("location").value("lng")
lat = Str(l1,"0.#######")
lng = Str(l2,"0.#######")
TextArea2.Text = lat + " / " + lng
I find using a JSON editor that displays and formats the string a requirement… looking at unformatted JSON just gives me a big headache. I use “JSON Editor” from Vlad Badea on my Mac… It makes seeing the “path” to the required value real easy.