Android Question Geocoding

hatzisn

Well-Known Member
Licensed User
Longtime User
Hello everybody,

I am experimenting with google geocoding. I have created a geocoding api key as described in this tutorial:
https://www.b4x.com/android/forum/threads/b4x-google-geocoding-rest-api.83870/

I also restricted the geocoding api key to my android application and specifically to Google Maps Geocoding API.
When I try to do reverse geocoding (coordinates to address) with the following code:

B4X:
    Dim hj As HttpJob
    Dim sRet As String
    hj.Initialize("Geocoding", Me)
    hj.Download2("https://maps.googleapis.com/maps/api/geocode/json", _
              Array As String("latlng", latitude & "," & longidude,"key","AIzaSyA-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))

I get the following json:

B4X:
{
   "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address xx.x.xxx.210, with empty referer",
   "results" : [],
   "status" : "REQUEST_DENIED"
}

What is the matter? I cannot figure out something.

Any help will be highly appreciated.
 

hatzisn

Well-Known Member
Licensed User
Longtime User
I just scrolled down in the tutorial as seen in the first post and saw Erel's answer on restricting the API KEY. Isn't it dangerous (for one's pocket) not to restrict the api key. Isn't there any workarounds?

Edit - I unrestricted the API KEY and it works. Any workarounds to restrict the api key and still work in my application?
 
Last edited:
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
I found a workaround. If I add a string variable in Main's activity process globals and set it to
the API KEY, I can compile to realease (obfuscated) and the string variable will be obfuscated.
I pass now the variable to the httpjob and get it done with the following code:

B4X:
Dim hj As HttpJob
    hj.Initialize("Geocoding", Module)
    hj.Download2("https://maps.googleapis.com/maps/api/geocode/json", _
              Array As String("latlng", latitude & "," & longidude,"key", Main.geoAK))

Am I correct?
 
Upvote 0
Top