How to use Google-Directions-Android library with a restricted API key

后端 未结 1 1892
深忆病人
深忆病人 2020-12-07 05:21

I am new to Android and working on a google map project. For this I am using this library to draw a route between two points.

This works fine when there is no restr

相关标签:
1条回答
  • 2020-12-07 05:33

    It looks like this library uses the Directions API web service, so you cannot use an Android-restricted API key. If you do, you get the request_denied error you're reporting. This is because web services are server-side and the API key can only be restricted by IP address.

    Having said that, you are calling the API from an Android app. Google's documentation states:

    IP restrictions might be impractical, such as in mobile applications and cloud environments that rely on dynamic IP addresses. When using Maps Web Service APIs in these scenarios, secure your apps using one or more of the following techniques:

    pinning, proxy server, obfuscation

    Hence, setting up a proxy server may be the best way to properly secure your API key.

    Hope this clarifies your question.

    0 讨论(0)
提交回复
热议问题