# Shortest route for multiple points

**URL:** https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508
**Category:** openrouteservice
**Created:** [January 17, 2022, 8:57am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508 "2022-01-17T08:57:46Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![kayhan](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/k/5e9695/32.png) [@kayhan](https://ask.openrouteservice.org/u/kayhan)
#### Post date: [January 17, 2022, 8:57am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/1 "2022-01-17T08:57:46Z")

</div>

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?  
Thankful

---

<div class="post-metadata">

### Author: ![kayhan](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/k/5e9695/32.png) [@kayhan](https://ask.openrouteservice.org/u/kayhan)
#### Post date: [January 17, 2022, 9:01am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/2 "2022-01-17T09:01:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jschnell](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/jschnell/32/971_2.png) [@jschnell](https://ask.openrouteservice.org/u/jschnell)
#### Post date: [January 17, 2022, 10:34am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/3 "2022-01-17T10:34:21Z")

</div>

Hey,

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](https://openrouteservice.org/dev/#/api-docs/optimization) - 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

---

<div class="post-metadata">

### Author: ![kayhan](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/k/5e9695/32.png) [@kayhan](https://ask.openrouteservice.org/u/kayhan)
#### Post date: [January 17, 2022, 8:04pm UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/4 "2022-01-17T20:04:19Z")

</div>

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.

[https://hub.gke2.mybinder.org/user/giscience-openrouteservice-py-3pl5hl43/notebooks/examples/basic\_example.ipynb#Optimization](https://hub.gke2.mybinder.org/user/giscience-openrouteservice-py-3pl5hl43/notebooks/examples/basic_example.ipynb#Optimization)

---

<div class="post-metadata">

### Author: ![jschnell](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/jschnell/32/971_2.png) [@jschnell](https://ask.openrouteservice.org/u/jschnell)
#### Post date: [January 18, 2022, 8:34am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/5 "2022-01-18T08:34:45Z")

</div>

Hey,

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

Best regards

---

<div class="post-metadata">

### Author: ![kayhan](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/k/5e9695/32.png) [@kayhan](https://ask.openrouteservice.org/u/kayhan)
#### Post date: [January 18, 2022, 9:57am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/6 "2022-01-18T09:57:40Z")

</div>

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

route = client.directions(  
coordinates=coordinates,  
profile=‘foot-walking’,  
format=‘geojson’,  
validate=False,  
optimize\_waypoints=True  
)

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

> <https://github.com/GIScience/openrouteservice-py/blob/master/examples/basic_example.ipynb>

---

<div class="post-metadata">

### Author: ![jschnell](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/jschnell/32/971_2.png) [@jschnell](https://ask.openrouteservice.org/u/jschnell)
#### Post date: [January 18, 2022, 9:59am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/7 "2022-01-18T09:59:04Z")

</div>

Hey,

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

Best regards

---

<div class="post-metadata">

### Author: ![kayhan](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/k/5e9695/32.png) [@kayhan](https://ask.openrouteservice.org/u/kayhan)
#### Post date: [January 18, 2022, 10:01am UTC](https://ask.openrouteservice.org/t/shortest-route-for-multiple-points/3508/8 "2022-01-18T10:01:09Z")

</div>

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