0
votes

I have an Android application and I am using the Google geocoding API to get GPS coordinates for an address. Currently I am using the following URL which works correctly:

http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=1600+Amphitheatre+Parkway,+Mountain+View,+CA

The problem is, will the above API continue to work after the Google's 'new pricing changes' starting July 16, 2018? According to the Google API documentation here, https://developers.google.com/maps/documentation/geocoding/intro#GeocodingResponses, the correct way to perform geocoding is using the following format:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

I have tried using the suggested format (created a project, enabled billing, enabled the Places and Maps APIs, created an API key, added security to the key so that only my app can access the key) but when I use the suggested format I get the error,

This IP, site or mobile application is not authorized to use this API key

Reading other questions on StackOverflow, I found the following suggestions, among others:

  1. Creating a server key and using it instead of the API key
  2. Not adding restrictions to the API key
  3. Using the first format of the API request (without the API_KEY)
  4. Wait for 10 minutes until the new KEY becomes active

I tried all of them except 1 and none works. Regarding solution #1, according to the documentation, the API needs an API key so I cannot see why a Server key would work.

Solution 2 is risky, solution 3 is not certain that it will continue to work with the pricing changes and solution 4 does not work either (I waited for hours without success).

I even created a new API KEY and added no restrictions to it and I got a limit exceeded error.

Can anyone provide any help on this?

2
Did Geocoder class (which should rely on user's quota) fail to operate in your case? developer.android.com/training/location/display-address - randomuser
The Geocoder function works fine. The thing is that what I want is to search by location name, not by lat/lon and the Geocoder class does not do that (as far as I know). - a.p.
It does, use getFromLocationName, it'll return a list of Address instance, which contain lat & long: developer.android.com/reference/android/location/… - randomuser

2 Answers

0
votes

Based on your comment above then the quickest approach would be to reverse geocode the address with Geocoder:

    if(Geocoder.isPresentt()){
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        List<Address> addresses;


        addresses = geocoder.getFromLocationName(addressName, 3);
        for(Address address : addresses){
            Log.d(TAG,"Lat:" + address.getLatitude() +", Lng: " + address.getLongitude());
        }
    }
0
votes

Using a proxy service (Solution #1) is the way to go if you are restricted to using the google Geocoding API.

Your app is being denied because google has no way of knowing what app is making the request with just the API key. If you look at the available API's, some say "for Android" and "for iOS", these are the ones that you can restrict and use natively.

Using a proxy will work (your assumption it won't is wrong) because you can restrict your API key to the IP of your service, and then require authorization from your app to use the proxy endpoint. This will protect your API key from being stolen and abused.