2

Let say that a user wants to tour the US. When I list the places I want to travel with the origin and destination, I want the Google API to make a route in the shortest way possible.

For Eg: My Origin: Las Vegas, Destination: New York. And the places I want to tour are Texas, Utah and Ohio. So I need the Google to connect the shortest distance to visit these places like from Las Vegas -> Utah -> Texas -> Ohio -> New York

Is this possible with Google Maps API / Directions API / Directions API?

I have searched the documentation, and it has documentation for origin and destination connect not the list of places as mentioned above.

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
SO-user
  • 1,458
  • 2
  • 21
  • 43
  • How many "waypoints" do you want to add? Will you add them in the correct sequence or do you expect the API to place these waypoints in a sequence that makes sense? – MrUpsidown Dec 19 '16 at 11:26
  • waypoints up to 15 and not in order. I want the waypoints in order. – SO-user Dec 19 '16 at 12:29
  • I now see that the documentation mentions you are limited to 23 waypoints. In the past, it used to be 8 (if I can remember correctly), so I wonder if this has changed or if this is a typo in the documentation... To be tested. https://developers.google.com/maps/documentation/javascript/directions#waypoint-limits – MrUpsidown Dec 19 '16 at 12:46

1 Answers1

0

You can use Waypoints and the optimizeWaypoints option to render a route that includes your waypoints and arranges them in a more efficient order.

By default, the Directions service calculates a route through the provided waypoints in their given order. Optionally, you may pass optimizeWaypoints: true within the DirectionsRequest to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.

https://developers.google.com/maps/documentation/javascript/directions#Waypoints

Below is a fiddle to help you get started with using waypoints.

JSFiddle demo

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
  • Change line 7 to `suppressMarkers: false`. And maybe a quick "thank you" for the help before complaining about something that is not to your liking? This is just a fiddle to help you get started. It's not supposed to be something you can copy/paste in your own code as it is. – MrUpsidown Dec 19 '16 at 14:04
  • Yes. Sorry for that.I was in a hurry get it done. Thanks a lot. – SO-user Dec 19 '16 at 14:08
  • Glad that it helped! – MrUpsidown Dec 19 '16 at 14:23