'Get the address Geo-Code for Google Maps
'Requires Street No as string, Street Name as string, Suburb as string, State as string - returns Lat/Long as string
Sub getGeoCode(streetno As String, street As String, suburb As String, state As String) As String
' https://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
'
parser.Initialize
Dim Googlekey As String = "AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxCE" '(my) google api key
Dim job As HttpJob
Dim poststring As String
'
' poststring = "address=1+Short+Street+South,+Sydney,+NSW&Key=" &Googlekey
street = street.Replace(",","+")
street = street.Replace(" ","+")
suburb = suburb.Replace(" ","+")
' build string from input text fields. Trim to get rid of crap
poststring = "address="&streetno.Trim&"+"&street.Trim&",+"&suburb&",+"&state&"&Key="
poststring = poststring & Googlekey
LogDebug(poststring)
'
job.Initialize("LatLong",Me)
job.PostString("https://maps.googleapis.com/maps/api/geocode/xml?" & poststring, "")
'gmap.
' maybe loop until latlong is returned with a value - this is a time delay
Return latlong
End Sub
Sub jobDone(job As HttpJob)
Dim in As InputStream
in = job.GetInputStream
'
parser.Parse(in,"Parser")
LogDebug("in = "&in&" Lat = "&lat&" Long = "&lng)
' lblLat.Text = lat
' lblLng.Text = lng
' gmap.AddMarker(lat,lng,"1 Short St")
' gmap.MapType = gmap.MAP_TYPE_NORMAL
' Dim cp As CameraPosition
' cp.Initialize(lat, lng, 12) 'lat, long, zoom level
' gmap.MoveCamera(cp)
'
' 'LogDebug("After Parser")
If job.Success Then
Select job.JobName
Case "LatLong"
Main.latlong = lat & "," & lng
LogDebug("job.getstring = "&Main.latlong)
' txtReply.Text = job.GetString
latlong = lat & "," & lng
'parser.
' break the string apart and get the lat/longs.....
Case "ZERO_RESULTS"
LogDebug($"No Results"$)
Case Else
LogDebug($"Error:${job.GetString}"$)
LogDebug($"No Results"$)
End Select
End If
'
End Sub
Sub parser_StartElement(Uri As String, Name As String, Attributes As Attributes ) 'Text As String
'LogDebug("parser begin")
If Name = "location" Then
'LogDebug("Location at start")
End If
End Sub
Sub parser_EndElement(Uri As String, Name As String, Text As StringBuilder)
If parser.Parents.IndexOf("location") > -1 Then
If Name = "lat" Then
lat = Text.ToString
End If
If Name = "lng" Then
lng = Text.ToString
End If
LogDebug("Location at end")
End If
'LogDebug("parser end")
End Sub