Hi guys,
I have enabled the Geocoding API in the console.developers.google.com site.
I am trying to get the longitude & latitude from an address using Google's API.
It works great when I run the compiler in debug mode and use b4bridge to show it on my phone. But when I switch to release mode, it only returns '9999' and '9999' for the latitude and longitude.
Any idea what could be wrong, why it doesn't work in release mode?
Thanks in advance!
I have enabled the Geocoding API in the console.developers.google.com site.
I am trying to get the longitude & latitude from an address using Google's API.
It works great when I run the compiler in debug mode and use b4bridge to show it on my phone. But when I switch to release mode, it only returns '9999' and '9999' for the latitude and longitude.
Any idea what could be wrong, why it doesn't work in release mode?
Thanks in advance!
B4X:
Sub btnGetLatLong_Click
Wait For(PlaceToLatLon(txtAddress.Text.trim)) Complete (ll() As Double)
If ll(0) <> 9999 Then
Msgbox("Location: " & ll(0) & ", " & ll(1),"")
Else
Msgbox("Failed to geocode.","")
End If
End Sub
Sub PlaceToLatLon(Place As String) As ResumableSub
Dim res() As Double = Array As Double(9999, 9999)
Dim j As HttpJob
j.Initialize("", Me)
j.Download2("https://maps.googleapis.com/maps/api/geocode/json", Array As String("key","MyAPIKey", "address", Place))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim m As Map = jp.NextObject
If m.Get("status") = "OK" Then
Dim results As List = m.Get("results")
If results.Size > 0 Then
Dim first As Map = results.Get(0)
Dim geometry As Map = first.Get("geometry")
Dim location As Map = geometry.Get("location")
res(0) = location.Get("lat")
res(1) = location.Get("lng")
End If
End If
Else
Log("Error!")
End If
j.Release
Return res
End Sub
Last edited: