android - 如何使用具有受限 API key 的 Google-Directions-Android 库

标签 android google-maps github routes google-directions-api

我是 Android 新手,正在从事谷歌地图项目。为此,我使用 this库绘制两点之间的路线。

当对 google map api key 没有限制时,这可以正常工作。但是当限制应用于我的应用程序的包名称和 sha1 key 时,它不会显示路由。

它抛出一个异常说:

This IP, site or mobile application is not authorized to use this API key. Request received from IP address XX.XX.XXX.XXX, with empty referrer

有什么方法可以通过受限的 api key 使用这个库吗?我如何向该库添加引荐来源网址?

最佳答案

看起来这个库使用了 Directions API web service ,因此您不能使用受 Android 限制的 API key 。如果这样做,您会收到报告的 request_denied 错误。这是因为 Web 服务是服务器端的,API key 只能受 IP 地址限制。

话虽如此,您是从 Android 应用调用 API。 Google's documentation状态:

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

因此,设置代理服务器可能是正确保护 API key 的最佳方式。

希望这能澄清您的问题。

关于android - 如何使用具有受限 API key 的 Google-Directions-Android 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196465/

相关文章:

android - 无法将请求的类放入单个 dex 文件中,即使对于之前编译良好的早期提交也是如此

java - 将数据从文件读入hashmap Android

java - 谷歌地图 getdirections api - 折线

google-maps - Openstreetmaps (OSM) 和 Google Maps(卫星 View )的 map 图 block

ios - 带有设备方向/陀螺仪传感器的 iOS 版谷歌街景

Git 与 Remote Master merge

android - 如何在新开发者控制台中上传 apk 扩展文件

android - VM 在从缓存中获取图像时内存不足

git - 将自托管的 git 存储库镜像到 github.com(身份验证失败)

github - 如何从github API获取网站链接?