0
votes

I am using the google direction api to solve the travelling salesman problem.

Apparently the api takes a param called optimize:true and then return a "waypoint_order": [ 1, 0, 2, 3 ] telling you the best order of waypoints that optimizes the route.

Thing is, when you try to optimize the route, the API just does not work and you get NO_RESULTS.

For instance use this url to see how the API fails when the optimize:true| bit gets added.

NOT working (NO_RESULTS error):

https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJdd4hrwug2EcRmSrV3Vo6llI&destination=place_id:ChIJh1a5WhEMa0gRY1JU4PEam8Q&waypoints=optimize:true|place_id:ChIJPeqVDlONbEgRk4X1zrUsKDs|place_id:ChIJ_WegsaCYc0gRlCypaxXgLjs|&key=YOUR_KEY

WORKING (but not optimizing):

NOT optimizing url: https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJdd4hrwug2EcRmSrV3Vo6llI&destination=place_id:ChIJh1a5WhEMa0gRY1JU4PEam8Q&waypoints=place_id:ChIJPeqVDlONbEgRk4X1zrUsKDs|place_id:ChIJ_WegsaCYc0gRlCypaxXgLjs|&key=YOUR_KEY

Does anyone know if they stopped supporting routes optimization?

Thanks

1
I have seen it work. Please provide a minimal reproducible example that demonstrates what you are seeing.geocodezip

1 Answers

1
votes

Looks to me like that is a bug in the DirectionsService when you pass in PlaceIds. I replicated it with the Javascript API. Using addresses works:

  waypts = [];
  waypts.push({
  location: "Plymouth, UK", // {placeId:"ChIJPeqVDlONbEgRk4X1zrUsKDs"},
  stopover: true
  });
  waypts.push({
  location: "Bournemouth, UK", // {placeId:"ChIJ_WegsaCYc0gRlCypaxXgLjs"},
  stopover: true
  });
  var request = {
    origin: "London, UK", //{placeId:"ChIJdd4hrwug2EcRmSrV3Vo6llI"},
    destination: "Newquay, UK", //{placeId: "ChIJh1a5WhEMa0gRY1JU4PEam8Q"},
    waypoints: waypts,
    optimizeWaypoints: true,
    travelMode: 'DRIVING'
  };

fiddle using addresses (returns waypoint order=1,0)

But the same locations (I used these placeIds to get the addresses above) doesn't work using placeIds:

  waypts = [];
  waypts.push({
  location: {placeId:"ChIJPeqVDlONbEgRk4X1zrUsKDs"},
  stopover: true
  });
  waypts.push({
  location: {placeId:"ChIJ_WegsaCYc0gRlCypaxXgLjs"},
  stopover: true
  });
  var request = {
    origin: {placeId:"ChIJdd4hrwug2EcRmSrV3Vo6llI"},
    destination: {placeId: "ChIJh1a5WhEMa0gRY1JU4PEam8Q"},
    waypoints: waypts,
    optimizeWaypoints: true,
    travelMode: 'DRIVING'
  };

fiddle using placeId (returns ZERO_RESULTS)

might be related to this issue in the issue tracker: Issue 8979: Bug: Can't use combination of placeId and String for origin/destination