【问题标题】:How to optimise route in google map using Google map client java api.如何使用谷歌地图客户端 java api 优化谷歌地图中的路线。
【发布时间】:2016-11-11 12:35:52
【问题描述】:

我正在获取这样的纬度和经度列表的路线详细信息,

DirectionsRoute[] routes = DirectionsApi.newRequest(context)
                .mode(TravelMode).origin(startPoint).destination(endPoint)
                .waypoints(wayPoints).await();

但我得到的路线没有优化,所以我想通过使用谷歌 java 客户端 api 来优化路线。

在 google map javascript api 中,我们可以通过提供这样的布尔属性来优化

 {
  origin: LatLng | String | google.maps.Place,
  destination: LatLng | String | google.maps.Place,
  travelMode: TravelMode,
  drivingOptions: DrivingOptions,
  waypoints[]: DirectionsWaypoint,
  optimizeWaypoints: boolean
}

但是如何使用谷歌地图 java 客户端 api 来实现呢?

【问题讨论】:

    标签: java google-maps routing directions google-directions-api


    【解决方案1】:

    您可以使用optimizeWaypoints 方法。确保您使用最新 (0.1.16) 版本的 google-maps-services:

    dependencies {
        compile 'com.google.maps:google-maps-services:0.1.16'
    }
    
    <dependency>
        <groupId>com.google.maps</groupId>
        <artifactId>google-maps-services</artifactId>
        <version>0.1.16</version>
    </dependency>
    

    在您的代码中:

    DirectionsRoute[] routes = DirectionsApi.newRequest(context)
        .mode(TravelMode)
        .origin(startPoint)
        .destination(endPoint)
        .waypoints(wayPoints)
        .optimizeWaypoints(true) // Add this
        .await();
    

    【讨论】:

    • 感谢它的帮助,但是这个方法在谷歌地图服务版本 0.1.1 中是否可用
    猜你喜欢
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多