## Developer guides

### Influence routes with stopover and pass through points

For each waypoint in the request, the directions response appends an entry to the legs array to provide the details for stopovers on that leg of the journey.

If you'd like to influence the route using waypoints without adding a stopover, add the prefix via: to the waypoint. Waypoints prefixed with via: won't add an entry to the legs array, but will route the journey through the waypoint.

The following URL modifies the previous request such that the journey is routed through `21.024140,105.847483` without stopping:

```plaintext
https://dplace-api.themap.world/maps/api/directions/json?
origin=21.02593,105.846535&destination=21.021002,105.85399
&waypoints=via:21.024140,105.847483
&alternatives=true&mode=driving
```

The `via:` prefix is most effective when creating routes in response to the user dragging the waypoints on the map. Doing so allows the user to see how the final route may look in real-time and helps ensure that waypoints are placed in locations that are accessible to the Directions API.

References: Google Via waypoint

### Optimize your waypoint

By default, the Directions service computes a route through the provide waypoints in their given order. In addition, you can pass `optimize:true` as first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order. All waypoints must be stopovers for the Directions service to optimize their route

If you instruct the Directions service to optimize the order of its waypoints, their order will be returned in the `waypoint_order` field within the routes object. The `waypoint_order` field returns values which are zero-based.

The following example calculates a road journey from coordinate `21.02593,105.846535` to coordinate `21.021002,105.85399` using route optimization.

```plaintext
https://dplace-api.themap.world/maps/api/directions/json?
origin=21.02593,105.846535&destination=21.021002,105.85399
&waypoints=optimize:true|21.024140,105.847483|21.023324,105.850257
&alternatives=true&mode=driving
```

Inspection of the calculated route will indicate that calculation uses waypoints in the following waypoint order:

```plaintext
"waypoint_order": [ 2, 1 ]
```

References: Google Optimize your waypoint