【问题标题】:How to use Java Client Library Google Maps Services for DirectionsApi如何使用 Java 客户端库 Google Maps Services for DirectionsApi
【发布时间】:2017-04-24 07:39:30
【问题描述】:

我已经尝试了几天,找不到任何使用 Java Client Library for Google Maps Services 的示例 对于 DirectionsApi,我看过很多关于请求响应的教程,但我想使用这个库,因为它是由谷歌创建的并且是社区支持的。我在他们的 github 页面上看到了地理编码示例,并看到了库的参考站点,但不明白如何实现 DirectionsApi。 我在 Android 中使用它,地理编码示例工作正常。

【问题讨论】:

  • 由于 API Key [maps-apis.googleblog.com/2016/09/….请介绍代理服务器。并且,使用 Maher Nabeel 的 DirectionsAPI 优秀示例。希望这会有所帮助。
  • github 上的自述文件说这个库是使用代理服务器的绝佳选择,那么我该如何使用它呢?
  • 嗨,我也在努力学习如何使用这个库,如果你找到了有用的教程/示例来使用它,请告诉我。我正在使用 Gradle 以防万一,但实际上任何线索都会受到赞赏。另外,您是否设法使代理服务器选项起作用?谢谢
  • 嘿,是的,我找到了,但我写代码已经有一段时间了,不记得确切的部分,因为它是一个 android 项目,但我这里有链接可以帮助你,我会的尝试查看我的存储库并找到适合您的代码。查看这些测试,因为它们显示了您如何使用它们。 java-client-library-test-foldersThis 是我阅读的一篇博文my repo

标签: android google-maps client-library google-directions-api


【解决方案1】:

这是一个简单的sn-p

GeoApiContext context = new GeoApiContext().setApiKey("YOUR_API_KEY");

DirectionsApiRequest apiRequest = DirectionsApi.newRequest(context);
apiRequest.origin(new com.google.maps.model.LatLng(latitude, longitude));
apiRequest.destination(new com.google.maps.model.LatLng(latitude, longitude));
apiRequest.mode(TravelMode.DRIVING); //set travelling mode

apiRequest.setCallback(new com.google.maps.PendingResult.Callback<DirectionsResult>() {
    @Override
    public void onResult(DirectionsResult result) {
        DirectionsRoute[] routes = result.routes;

    }

    @Override
    public void onFailure(Throwable e) {

    }
});

要了解其他选项,请参阅文档: https://developers.google.com/maps/documentation/directions/intro

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 2017-12-31
    相关资源
    最近更新 更多