Shortest route for multiple points

Excuse me, I have a problem.

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?

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?

Thank you


this post is not related to the topic it was previously in, so I moved it to a new one :slight_smile:
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.

Best regards

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.


the link you provided seems to not work - are you sure it’s correct?

Best regards

You can see this page.
At the bottom of the page, the title Optimization.

route = client.directions(

For the shortest route by car, I set profile = ‘driving-car’.


yes, that should work.
Did you try it? Did you encounter any problems?

Best regards

Yes, I tried it and it works fine.
Thank you

1 Like