Android Google Maps Direction Api - Api key restriction not working

google maps api key
google maps api key without billing
this api project is not authorized to use this api.
google maps directions api android example
google directions api
google direction api key
google api
google directions api pricing

When we are setting a Key restriction to NONE for Google Maps Direction Api, It works fine.

But When we set Key restriction to Android apps and provide a proper Package name & SHA-1 certificate - It says Request Declined from Google Api response.

Any known solution to this?

Directions API is a web service. The restrictions that will work with an API keys for web services are IP restrictions.

It is supposed that web services requests are executed on your backend servers. If you need to restrict an API key, the workaround is to create an intermediate server. Your Android application should send requests to the intermediate server, intermediate server should send requests to Google and pass responses back to your app. In this case you can restrict an API key by IP address of your intermediate server.

Have a look at this document:

Hope this clarifies your doubt.

Get an API Key | Directions API, API restrictions. Select Restrict key. Click Select APIs and select Maps SDK for Android. (If the Maps SDK for Android is not listed, you need to enable it.). The restriction becomes part of the API key definition after this step. If you fail to provide the appropriate details or do not click “Save”, the API key will not be restricted. (For further information, see the Get an API Key guide for the specific API or SDK you are interested in.) To set an API restriction for an API key

You will usually have more than one certificate. One for debug and one for release.

Ensure that you add both fingerprints or that the certificate fingerprint you are using matches the one for the buildType you specified

API Key Best Practices, API enabled. To learn more, see Get Started with Google Maps Platform. Note: The Places API does not work with an Android or iOS restricted API key. I switched all static map request code to MapBox and realize my Google Maps Static API Static Maps didn’t decrease while my MapBox Static Images API call is only around 30K. I suspect someone is stealing my API Key and try to check for some clue at Google Maps-> Metrics and select Maps Static API from the drop down.

Please try with compile 'com.akexorcist:googledirectionlibrary:1.1.1' flow the doc or try this method And 2nd method Set CameraWithCoordinationBounds for animate Camera:

private void drawMap(double s_lat,double s_lng,double e_lat,double e_lng) {
        Log.e("map", "++");
        List<LatLng> waypoints = Arrays.asList(

                new LatLng(22.626390800000003, 88.4313014), new LatLng(22.619708499999998, 88.4369083)
        GoogleDirection.withServerKey("AIz... your google api key")
                .from(new LatLng(s_lat, s_lng))
                .to(new LatLng(e_lat, e_lng))
                .execute(new DirectionCallback() {
                    public void onDirectionSuccess(Direction direction, String rawBody) {
                        if (direction.isOK()) {
                            com.akexorcist.googledirection.model.Route route = direction.getRouteList().get(0);
                            int legCount = route.getLegList().size();
                            for (int index = 0; index < legCount; index++) {
                                Log.e("map", "++++" + index);
                                Leg leg = route.getLegList().get(index);
                                // mMap.addMarker(new MarkerOptions().position(leg.getStartLocation().getCoordination()));

                                if (index == 0) {
                                    Log.e("position","0" + leg.getStartLocation().getCoordination());
                                    //   mMap.addMarker(new MarkerOptions().position(leg.getEndLocation().getCoordination()).title("User"));
                                    mMap.addMarker(new MarkerOptions().position(leg.getStartLocation().getCoordination()).icon(BitmapDescriptorFactory
                                } else if (index == legCount - 1) {
                                    //   mMap.addMarker(new MarkerOptions().position(leg.getEndLocation().getCoordination()).title("User"));
                                    mMap.addMarker(new MarkerOptions().position(leg.getEndLocation().getCoordination()).icon(BitmapDescriptorFactory
                                } else {
                                    mMap.addMarker(new MarkerOptions().position(leg.getEndLocation().getCoordination()).icon(BitmapDescriptorFactory
                                List<Step> stepList = leg.getStepList();
                                ArrayList<PolylineOptions> polylineOptionList = DirectionConverter.createTransitPolyline(MainActivity.this, stepList, 5, Color.RED, 3, Color.BLUE);
                                for (PolylineOptions polylineOption : polylineOptionList) {
                            setCameraWithCoordinationBounds(route); // animateCamera


                    public void onDirectionFailure(Throwable t) {

                        Log.e("error", t.getLocalizedMessage() + t.getMessage() + "");
                        // Do something

  private void setCameraWithCoordinationBounds(com.akexorcist.googledirection.model.Route route) {
        LatLng southwest = route.getBound().getSouthwestCoordination().getCoordination();
        LatLng northeast = route.getBound().getNortheastCoordination().getCoordination();
        LatLngBounds bounds = new LatLngBounds(southwest, northeast);
        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));

Directions API: Get an API Key, Google Maps SDK for Android Printing from the Maps JavaScript API is not supported. 5 p.m. Pacific time) excluding regional holidays for "service unusable" issues. Platform APIs are billed, please see Understanding billing for Maps, Routes, and Places. Places SDK for Android, API key with Android restriction. While I was going through this blog, I got confused about using the Directions API on android.Is it possible to integrate the Directions API on the Map? To make it more clear, I am working on an application that would take in inputs from the users for things like source and destinations taking these inputs I would like to display an appropriate map having both the walking and driving

Get an API Key | Maps SDK for Android, Application restriction: Limits usage of the API key to either websites (HTTP referrers), web servers (IP addresses), or mobile apps (Android apps or iOS apps ). Copy the resulting API key, go back to Android Studio, and paste the API key into the <string> element in the google_maps_api.xml file. A slightly less fast way: Use the credentials provided in the google_maps_api.xml file that Android Studio created for you: Copy the credentials provided in the google_maps_api.xml file.

Get an API Key | Places API, Calculate directions between locations using the Google Maps Directions API. service via your server when you're using the API in a mobile app, to protect your API key. Your browser does not currently recognize any of the video formats available. For more information see Route Restrictions below. language — The � On the Credentials page, click the name of the API key that you want to secure. On the Restrict and rename API key page, set the restrictions: Application restrictions; Select IP addresses (web

Google Maps Platform FAQ, Reminder: To use the Directions API, you must include an API key with all API requests How usage and billing work under the pay-as-you-go model The request does not include stopover waypoints. for the Directions API, and the License Restrictions section of the Google Maps Android � iOS � Web � Web Services� The API key created dialog displays your newly created API key. Click Close. The new API key is listed on the Credentials page under API keys. (Remember to restrict the API key before using it in production.) Note: You can use the same API key for your Maps SDK for Android and Places SDK for Android apps. Add the API key to your app. Add the

  • in debug or live?
  • for both it's not working.
  • So What I conclude is that without intermediate server Any one with a Api key can make a request and get successful response of Direction Api. But what about the SHA-1 finger print they are asking for then? There should be ony 2 options : A) NONE B) Server IP address
  • Android app restriction with SHA1 is used for Google Maps Android API only, the IP restriction is used for web services (Geocoding API, Directions API, etc.). In order to protect an API key used by web service you must send requests from the server that you own and use its IP as a restriction.
  • I am finding it strange that Google Map Direction Api key can't be restricted by Android App itself by providing unique fingerprint. But so far it's the best answer I can have. So I am thankful to you & accepting your answer.
  • I did that buddy. I have tried with only debug - but after unsuccessful effort I did go with release. But failed for both.
  • Can you explain from your answer that How is it suppose to restrict the key?