Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps Direction Api - Api key restriction not working

enter image description here

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?

like image 345
Sagar Shah Avatar asked Sep 12 '17 13:09

Sagar Shah


People also ask

Why isn't my Google Maps API working?

There are a several reasons why your google maps may not be working, the most common issue being no Google Map API key set or set incorrectly. To use the Google Maps JavaScript API, you must register your app project on the Google Cloud Platform Console and get a Google API key which you can add to your app.

How do I use Google Directions API on Android?

Choose or create a project, enable billing, and enable the Directions API. See Set up in the Cloud Console. Create and restrict an API key, and add it to your code. See Use an API Key.


1 Answers

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:

https://developers.google.com/maps/faq#using-google-maps-apis

Hope this clarifies your doubt.

like image 130
xomena Avatar answered Oct 23 '22 13:10

xomena