How to Add Multiple Stops to a Route

API or service
Routing API + Route Planner API
Task
Stops → ordered or optimized multi-leg route
Examples
URL
Difficulty
Beginner
Time
7 min

Add multiple stops to a route

You have an origin, a destination, and one or more intermediate stops that must be visited in a known order. The Routing API calculates the road route through those waypoints and returns one route leg between each pair of stops.

By default, the request preserves the waypoint order. Set optimize_stops=true when one route has flexible intermediate stops and the Routing API should find a better visit order while keeping the origin and destination fixed. Use the Route Planner API for operational planning across jobs, shipments, or multiple agents.

Task flow: ordered stops → Routing API → route geometry, total distance and time, and one leg per stop pair.

Route through ordered stops

Put the origin first, the destination last, and intermediate stops between them. Separate waypoints with |; each default coordinate pair uses latitude,longitude order.

https://api.geoapify.com/v1/routing?waypoints=50.679023,4.569876|50.671000,4.575000|50.661705,4.578667&mode=drive&format=json&apiKey=YOUR_API_KEY

This request visits the three Belgian waypoints in exactly the supplied order and produces two legs.

Reduced response:

{
  "results": [
    {
      "distance": 3166,
      "time": 407.367,
      "legs": [
        {
          "distance": 1912,
          "time": 175.662
        },
        {
          "distance": 1254,
          "time": 231.704
        }
      ]
    }
  ]
}

Distances are meters and times are seconds with the default metric units. The route total equals the sum of its legs: 1912 + 1254 = 3166 meters.

Choose an optimization request (optional)

Skip this step when the default balanced route and supplied waypoint order already meet the application's needs. Otherwise, choose the request that matches what should be optimized.

Prefer a different road path

Use the Geoapify Routing API type parameter to change the preferred path between stops without changing their order.

https://api.geoapify.com/v1/routing?waypoints=52.5163,13.3777|52.5219,13.4132|52.5096,13.3760|52.5050,13.4397&mode=drive&type=short&format=json&apiKey=YOUR_API_KEY

Use type=balanced for the default balance of time and distance, type=short to prioritize distance, or type=less_maneuvers to penalize turns for motorized road modes. The Geoapify Routing API visits the waypoints in the supplied order.

Reorder intermediate stops

Add optimize_stops=true when the first and last waypoints must remain fixed but the intermediate stops may change order.

https://api.geoapify.com/v1/routing?waypoints=52.5163,13.3777|52.5219,13.4132|52.5096,13.3760|52.5076,13.3904|52.5050,13.4397&mode=drive&optimize_stops=true&type=balanced&format=json&apiKey=YOUR_API_KEY

The Geoapify Routing API keeps waypoint indexes 0 and 4 fixed and may reorder indexes 1, 2, and 3. You can combine optimize_stops=true with any supported type value.

Optimize work across agents

Use the Geoapify Route Planner API when jobs or shipments must be assigned and ordered across one or more vehicles or workers.

POST https://api.geoapify.com/v1/routeplanner?apiKey=YOUR_API_KEY
Content-Type: application/json
{
  "mode": "drive",
  "agents": [
    {
      "id": "technician-a",
      "start_location": [13.4132, 52.5219]
    }
  ],
  "jobs": [
    {
      "id": "inspection-101",
      "location": [13.3777, 52.5163],
      "duration": 900
    }
  ]
}

Geoapify Routing API query waypoints use latitude,longitude order. Geoapify Route Planner API request coordinates use GeoJSON [longitude, latitude] order. After planning, send each agent's ordered waypoints to the Geoapify Routing API when you need detailed route geometry or turn-by-turn directions.

For a complete stop-order example, see How to Optimize the Order of Stops in a Route. For jobs, shipments, capacities, skills, or schedules, see the Geoapify Route Planner API documentation.

Request encoded route geometry (optional)

The Geoapify Routing API returns GeoJSON route geometry by default. Add details=polyline5 or details=polyline6 when you also need a compact path to store, transfer, pass to a library that accepts encoded polylines, or use as a route-corridor filter with the Geoapify Places API. See How to Find Restaurants, Fuel Stations, or Parking Along a Route for the route-corridor workflow.

Request precision-6 geometry

https://api.geoapify.com/v1/routing?waypoints=43.424923,-123.298537|43.261954,-123.350676|43.120223,-123.398972&mode=drive&details=polyline6&apiKey=YOUR_API_KEY

Read the complete path from features[0].properties.polyline6. Each leg also has features[0].properties.legs[legIndex].polyline6.

When using format=json, read the same values from results[0].polyline6 and results[0].legs[legIndex].polyline6.

Request both precisions

Request both formats only when separate consumers require different precision:

https://api.geoapify.com/v1/routing?waypoints=43.424923,-123.298537|43.261954,-123.350676|43.120223,-123.398972&mode=drive&details=polyline5,polyline6&apiKey=YOUR_API_KEY
  • polyline5 uses five-decimal encoded-polyline precision.
  • polyline6 uses six-decimal encoded-polyline precision.
  • A consumer must decode the path with the same precision that the request returned.

The route-level path joins all legs in travel order without duplicating their shared endpoints. The same requests are available through the EU-only https://api-eu.geoapify.com/v1/routing endpoint, where requests are processed exclusively within the European Union.