I use the above method to find the shortest path.
But this method does not necessarily suggest the shortest route, because it suggests the path in the order of places.
For example, if I have the following coordinates:
Coordinates = [point1, point2, point3, point4]
The shortest path may be as follows:
point1, point4, point2, point3
But the above method does not work this way.
what should I do?
Thankful
Excuse me, I have a problem.
I use the above method to find the shortest path between several points.
But the proposed route is not the shortest path.
For example, my coordinates are as follows:
Coordinates = {point 1, point 2, point 3, point 4}
And the program suggests the path between points 1,2,3,4 in “order”. But in fact, the shortest path is 1,3,2,4 !!!
How do I write code to display the shortest path between multiple points?
this post is not related to the topic it was previously in, so I moved it to a new one
As for your question:
If you pass multiple points to the directions API, it’ll give you the shortest route between the points in the order you provided. Thus, the route from 1 to 2 will be the shortest it can be, the route from 2 to 3 as well, and so on.
This does of course not mean that it is the optimal route to traverse all points.
For this, have a look at the optimization endpoint - its used to solve a more general problem, but using just one vehicle and no other constraints, it should be able to solve your problem.
Thank you very much for your guidance
I searched and found the following tutorial.
If this tutorial is correct and provides the shortest path, please confirm.
I write the link for others to use.