android - 从 Android 设备调用方向 API 的谷歌地图错误

标签 android google-maps google-directions-api

我正在使用适用于 Android 的 Google map v2。我想调用 directions api 从 android 设备获取积分。我注册了谷歌控制台 key ,我可以在安卓上查看 map 。我使用此键在指示 api 调用中包含如下内容:

https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false&key=API_KEY

API_KEY 是我为 map 创建的 key :

api key for maps and directions

但是当我从 android 应用请求调用 directions api 时,我得到了这个返回:

{
   "error_message" : "This IP, site or mobile application is not authorized to use this API key.",
   "routes" : [],
   "status" : "REQUEST_DENIED"
}

我该如何解决这个错误?请帮忙

谢谢

最佳答案

这是调用获取两个地理点之间的方向路径的正确 URL。

http://maps.googleapis.com/maps/api/directions/json?origin=23%C2%B0%201%27%2050.49711640%22%2C%2072%C2%B0%2034%27%2014.520786762%22&destination=22%C2%B0%2017%27%208.23132830%22%2C%2073%C2%B0%2012%27%2026.766651630%22&sensor=true&mode=driving

不需要通过KEY=api-key在方向 URL..

所以,请删除此参数。并按照上面的方式调用 URL。 api key 只放在<meta-data> list 文件中的标记。

请调用此 URL:

https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false

希望对你有用。

关于android - 从 Android 设备调用方向 API 的谷歌地图错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22395465/

相关文章:

android - 应用程序在 android 上的信息亭模式

android - 使移动设备看起来像电脑到网页

java - 我如何将直接从 Google Place API 获取的地址组件明智地 fork ?

android - 如何在 android 的谷歌地图中选择不同的路线?

r - Googleway R 替代路线

javascript - 将 item-left-edit 更改为 item-right-edit 为 Ionic

android - Gradle构建卡在app:tranformDexArchiveWithDexMergerForDebug

javascript - FusionTablesLayer 多边形与 styleId 点击事件未触发

java - 我们可以在java桌面应用程序中使用离线谷歌地图吗?

iOS:两个位置之间的路线距离(路线,不是直线)