如何找到在 android 应用程序中两地之间旅行所需的时间

How to find the time it will take to travel between two places in an android app

我正在做一个学校项目,需要计算在两个地点之间旅行所需的时间,最好是在 android 应用程序中指定交通方式的选项。

我遇到了 Google 距离矩阵 API(文档 here),它似乎具有我正在寻找的功能,但它警告...

"If you are building a mobile application, you will need to introduce a proxy server to act as intermediary between your mobile application and the Google Maps API Web Services."

我知道这是为了保护 API 密钥,并希望非常努力地遵循这一点。我想知道,有没有另一种方法可以在不设置代理服务器的情况下获取应用程序所需的数据?

我知道我可以使用像 Heroku 这样的服务来 运行 访问 API 的代码,但这似乎是一个困难的选择,因为这只是一个学校项目。关于如何为我的应用获取行程时间还有其他想法吗?

设置代理服务器是保护 API 密钥的最佳方式,但 Google 还建议采用其他安全技术,例如 obfuscation and pinning

话虽如此,如果这是一个学校项目并且您不会在生产环境中制作 API 密钥 public,那么您可以留下 API 密钥不受限制(并且没有代理服务器)。

但请确保您 monitor your API usage on a regular basis and that you regenerate your API key periodically and/or as needed. It's also strongly recommended that you set daily quota limits and budget alerts as per this FAQ 无论如何都不会超出预算。

希望对您有所帮助!