Google MAPS waypoints

2019-08-30 07:27发布

问题:

I have a problem using waypoints in Google Maps: https://developers.google.com/maps/documentation/javascript/directions#DirectionsResults

I want to add waypoints and get driving directions in the order I provide them, but google automatically optimize them...

I send request with this code:

var request = {
  origin: start,
  destination: end,
  waypoints: waypts,
  optimizeWaypoints: true,
  travelMode: google.maps.TravelMode.DRIVING
};

and in my array (waypts) waypoints are ordered as they should be ...

Example:

I want to go from NY via Chicago via NY to Philadelphia.. But the response I get is like this: NY via NY (1 meter) to Chicago to Philadelphia. Google somehow optimize route but I don't want this ...

Any idea?

Thanks!

回答1:

LOL ... I missed that in documentation... The solution is:

In var request put the line:

optimizeWaypoints: false


回答2:

Or just simply removing this line:

optimizeWaypoints: true


标签: maps