I am writing a android application with a map from google. Wrote a code to request a route using "google-maps-services: 0.2.7" . Intermediate points are transmitted as a string, the path optimization parameter is specified, but the route is still constructed according to the sequence of points indicated.

Request Code:

String waypointsString = ""; for(int i = 0; markersList.size() > i; i++){ waypointsString += markersList.get(i).latitude + "," + markersList.get(i).longitude + "|"; } String cur_pos_coords = latitude + "," + longitude; GeoApiContext geoApiContext = new GeoApiContext.Builder() .apiKey(mapsApiKey) .build(); DirectionsResult result = null; try { result = DirectionsApi.newRequest(geoApiContext) .mode(TravelMode.WALKING) .origin(cur_pos_coords)//Место старта .destination(cur_pos_coords)//Пункт назначения //.waypoints(markersList.get(0).latitude + "," + markersList.get(0).longitude+ "|"+ markersList.get(1).latitude + "," + markersList.get(1).longitude+"|"+markersList.get(2).latitude + "," + markersList.get(2).longitude) .waypoints(waypointsString) .optimizeWaypoints(true) .language("ru") .await(); } catch (InterruptedException | IOException | ApiException e) { e.printStackTrace(); } 

I get the answer, I write the order to the array, but the order has not changed, that is, there was no way to optimize

 int[] ar = result.routes[0].waypointOrder; for (int i = 0; i < ar.length; i++) { Log.d("Point #" + i, "" + ar[i]); addMarker(markersList.get(ar[i]).latitude, markersList.get(ar[i]).longitude, i, "Задача №" + ar[i]); } 

Thanks in advance for the answers.

UPD

The solution was found by adding to the beginning of the line with the coordinates of the passage "optimize: true |" and commenting on the line calling the .optimizeWaypoints (true) method. As a result, we got such a call:

  result = DirectionsApi.newRequest(geoApiContext) .mode(TravelMode.WALKING) .origin(cur_pos_coords)//Место старта .destination(cur_pos_coords)//Пункт назначения .waypoints("optimize:true|" + waypointsString) //.optimizeWaypoints(true) .await(); 
  • At the same time, are you sure that there is a more optimal route to these points? - iksuy 2:29 pm
  • show output from result? especially from geocoder_status - Serge Markov
  • There is an optimal route, since one of the points is too far from the starting point. - nar10z
  • @SergeMarkov answer is positive. Case request is checked by direct link in chrome, the answer came with optimized points - nar10z

0