简体   繁体   English

如何使用Google Map Client Java API优化Google Map中的路线。

[英]How to optimise route in google map using Google map client java api.

I am getting route details for list of latitude and longitudes like this, 我正在获取类似这样的经纬度列表的路线详细信息,

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

But the routes that i am getting are not optimised so i want to optimise route by using google java client api. 但是我得到的路由没有经过优化,因此我想通过使用Google Java Client API优化路由。

In google map javascript api we can optimise by giving boolean attribute like this 在google map javascript API中,我们可以通过提供boolean属性来优化,例如

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

But how to achieve this using Google maps java client api? 但是如何使用Google Maps Java Client API实现此目标?

You can use the optimizeWaypoints method. 您可以使用optimizeWaypoints方法。 Make sure that you use the latest (0.1.16) version of google-maps-services: 确保您使用的是最新(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>

In your code: 在您的代码中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM