Android Question Google gecode API works on debug mode, but not on release mode

Jakes72

Member
Licensed User
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!


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:

Jakes72

Member
Licensed User
Update on my problem, it looks like google only allows me 1 request a day as I looked at the returned JSON and the status says: OVER_QUERY_LIMIT.
Is this normal? How do I overcome this?
 

Syd Wright

Well-Known Member
Licensed User
Update on my problem, it looks like google only allows me 1 request a day as I looked at the returned JSON and the status says: OVER_QUERY_LIMIT.
Is this normal? How do I overcome this?
See this: https://developers.google.com/maps/premium/previous-licenses/articles/usage-limits and: https://stackoverflow.com/questions/14014074/google-maps-api-over-query-limit-per-second-limit

Likely you are sending too many requests per second (or, less likely, per day).
The quotas are respectively 1 query per second and 25.000 per day.

Another advice: You should not show your API key in code samples.
 
Last edited:

Jakes72

Member
Licensed User
Hi Syd,

Thanks for the reply and the advice about my key. The thing is that I am only pushing the button exactly once, so I should only be making one request. How come i am going over the limit?
 

BillMeyer

Well-Known Member
Licensed User
@Jakes72 ,
2 things from previous experience:
1. Did you fill in your billing information on an active credit card ?
2. Did you activate the correct API ?
 

DonManfred

Expert
Licensed User
Thanks for the reply and the advice about my key. The thing is that I am only pushing the button exactly once, so I should only be making one request. How come i am going over the limit?
every user which calls this api without an own key are using the free quota. ALL which are using it AROUND the World. If 30.000 people do it once a day the last 5000 did get an error
 
Last edited:

Syd Wright

Well-Known Member
Licensed User
Hi Syd,

Thanks for the reply and the advice about my key. The thing is that I am only pushing the button exactly once, so I should only be making one request. How come i am going over the limit?
If the shown API key is not your personal Google Maps key then you should immediate get your own key.
The second link I gave you describes how to test whether you are exceeding a seconds quota or a daily quota: simply wait 2 seconds before doing another query. If you still get the quota error then you have succeeded your daily quota.
There is no way to circumvent the quotas, but you can use some tricks as described in my second link.
 

Jakes72

Member
Licensed User
Hi Everyone, thanks for the help and suggestions.
I eventually got this too work by using the 'Geocoder' library which another member kindly created.

I post my code here to help anyone else battling with this:

B4X:
Sub btnGetLatLong_Click
                             
       'The 'Geocoder_GeocodeDone' sub will fire once the adddress has been decoded to latitude & longitude co-ords.
        GeoCoder.GetFromLocationName(txtAddress.Text.Trim,5, Null)

End Sub


Sub Geocoder_GeocodeDone(Results() As Address, Tag As Object)
           
                   
            If Results.Length>0 Then
                Dim Address1 As Address
                Dim i As Int
                For i=0 To Results.Length-1
                    Address1=Results(i)
                Next
              
                Msgbox(Address1.Latitude,"")
                Msgbox(Address1.Longitude,"")
       
            Else
            
               Msgbox("GetFromLocation", "No Address matched the Latitude and Longitude")
           
            End If
                   
 End Sub
 

DonManfred

Expert
Licensed User

Jakes72

Member
Licensed User
Hi Don, well so far the Geocoder library is working for me, I just tested it this morning.
But as a matter of interest how would I use the Rest API to implement this, I do not have a clue, I'm still a noob :)
 
Top