12
votes

Sometimes when I try to use the Google MAPS API KEY to get a URL to draw a 'polyline', i get an error in my logs:

"error_message":"Keyless access to Google Maps Platform is deprecated. Please use an API key with all your API calls to avoid service interruption. For further details please refer to http://g.co/dev/maps-no-account","routes":[],"status":"OVER_QUERY_LIMIT"

I have this in my manifest:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="MY_GOOGLE_MAPS_API_KEY" />

Also, this API KEY 'enabled' in my API CONSOLE and it is restricted to Google Maps Android SDK and Directions API. I also have billing enabled for my Google API CONSOLE but I still get this error sometimes.

4
Double check if you use web service (Directions API) with an API key. What is your request to get directions? Also note that Android SDK and Directions API cannot use the same API key, because Android SDK requires Android app restriction while Directions API requires an IP address restriction.xomena
@xomena Turns out my issue was happening because I wasn't using the API KEY in the JSON request. For example, I was getting my error when I was doing this: String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters; But to fix it, I did this: String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters + "&key=" + MY_API_KEY; I guess google reccomends us to use API Key directly in these sort of JSON requests to prevent quota errors.grantespo

4 Answers

27
votes

Since June 11th 2018, Google began enforcing the use of API keys. Keyless usage will result in a degraded experience, or an error like OVER_DAILY_LIMIT and OVER_QUERY_LIMIT.

Source: Important Updates from Google Maps Platform

Putting the API Key in the URL like this is a good solution:

String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters + "&key=" + MY_API_KEY

But be sure that your key restrictions are well configured. If you have restricted the Key to your app, it may not work because the request made via HTTP are related with your IP address. Meaning that even if you have correctly configured your Android App and manifest, it may result with an ACCESS_DENIED. This can be verified by changing your restriction.

Example of no restriction for testing purpose: enter image description here

For more details about API key and restrictions: Quick guide to getting a key

4
votes

For the ones that use jd-alexander's direction library, don't forget to add the api key to routing builder:

Routing routing = new Routing.Builder()
                .travelMode(/* Travel Mode */)
                .withListener(/* Listener that delivers routing results.*/)
                .waypoints(/*waypoints*/)
                .key(/*api key for quota management*/)
                .build();
    routing.execute();
1
votes

If anyone using jd-alexander's Google Directions Library use the Google API key as below code.

Routing routing = new Routing.Builder()
                .key(YOUR_KEY)
                .travelMode(AbstractRouting.TravelMode.DRIVING)
                .withListener(this)
                .alternativeRoutes(false)
                .waypoints(SourceLatLng, DestinationLatLng)
                .build();
        routing.execute();

If you have any doubts don't hesitate to leave a comment.

-1
votes

I just added the key parameter in the url. After that I can able to get the response from Google Map API.

Example: https://maps.googleapis.com/maps/api/geocode/json?address=COMPLETE+ADDRESS&sensor=true&key=YOUR_GOOGLE_MAP_API_KEY