The shortest route without a destination in Google Maps V3?

So, I'm just learning javascript to communicate with the Google Maps API. I was wondering if anyone has an elegant solution to this problem that I am facing.

A Google Maps route request should contain three things (origin, destination, and travelMode). My TravelMode will always be TRAFFIC. The origin will always be where the user is.

The purpose, however, must be changed. I have several waypoints, and the user will visit and would like to provide the shortest possible trip depending on which route points are selected and where the user is, ending the route on one of the waypoints (for example: ABC or ACB, but always Axx. ..J).

Is there any possible way to do this differently than to calculate all the possible paths and see that it has the shortest distance (or time, or what I am evaluating)? It seems like it would be prohibitively expensive (O (n!)).

edit: with optimizeWaypoints set to true, this becomes an O (n) problem instead of O (n!), but now I am having problems issuing too many requests in too short a period of time.

+4
source share
3 answers

, Google distanceMatrix API .

API- .

+2

A simple solution would be to set Departure and Destination as the same thing and ask Google Maps to optimize the route based on all other waypoints. Usually, he first either goes to the farthest point, or to the last, and then returns to the origin. Then you can make another request without optimization, this time specifying the destination as the last optimized waypoint.

0
source

Source: https://habr.com/ru/post/1771828/


All Articles