Fleet route optimisation (VRP)
The dispatcher's problem: n vehicles, m stops. The API decides which vehicle takes which stops and in what order — within capacity, time windows and working hours.
Scenario: Last-mile delivery — 1 depot, 3 vehicles, 8 customers
The problem most callers actually have: one depot, several vehicles, one day of individual orders. Two small vans carry 12 boxes each and a smaller one carries 4; eight customers need 18 boxes in total, each stop takes 5–15 minutes, and four will only accept delivery in a given morning or afternoon window. In the answer: the solver splits eight orders across three vehicles, each leg is named after its customer, arrivals fall inside the promised windows, and the line on the map is the road actually driven. Switch "Routing profile" to Motorbike to watch the distance drop — note that the whole fleet shares one profile.
- The API returns routes — one per vehicle, listing the legs in driving order with the arrival time and what is still on board after each.
- Anything no vehicle can take lands in unassigned instead of failing the whole solve — that is how you learn you are short a van or have over-constrained the problem.
Orders (8)
The API echoes this onto each leg — easier to read than an order id
Type "latitude, longitude", or use the icon to pick on the map
Loaded at the depot and unloaded at this stop
Picked up at this stop and carried back to the depot
How long the vehicle stays to hand over the goods; counted in the total
Leave empty for any time; arriving early means waiting
0 = drop it if short on vehicles · 10 = must be delivered
Only a matching vehicle can take this order
Vehicles (3)
Shown on the route instead of "Vehicle #1"
Type "latitude, longitude", or use the icon to pick on the map
The load on board may never exceed this
Leave empty to drive at any hour
Decides which orders this vehicle can take
Returning to the depot counts the trip back into the distance
Shown on the route instead of "Vehicle #1"
Type "latitude, longitude", or use the icon to pick on the map
The load on board may never exceed this
Leave empty to drive at any hour
Decides which orders this vehicle can take
Returning to the depot counts the trip back into the distance
Shown on the route instead of "Vehicle #1"
Type "latitude, longitude", or use the icon to pick on the map
The load on board may never exceed this
Leave empty to drive at any hour
Decides which orders this vehicle can take
Returning to the depot counts the trip back into the distance
One colour per vehicle. Lines are the legs between stops, not the real road geometry.
Code samples
curl -X POST 'https://maps.vietmap.vn/api/vrp?api-version=1.1&apikey=YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jobs": [
{
"id": 1,
"location": [
106.70592,
10.79628
],
"service": 600,
"description": "Cửa hàng Bình Thạnh",
"delivery": [
3
],
"time_windows": [
[
28800,
39600
]
]
},
{
"id": 2,
"location": [
106.7066,
10.80189
],
"service": 900,
"description": "Siêu thị mini Điện Biên Phủ",
"delivery": [
4
]
},
{
"id": 3,
"location": [
106.68982,
10.80159
],
"service": 600,
"description": "Quán ăn Phú Nhuận",
"delivery": [
2
],
"time_windows": [
[
32400,
43200
]
]
},
{
"id": 4,
"location": [
106.695,
10.785
],
"service": 300,
"description": "Nhà khách Quận 3",
"delivery": [
1
]
},
{
"id": 5,
"location": [
106.712,
10.7905
],
"service": 600,
"description": "Kho lẻ Thủ Đức",
"delivery": [
3
],
"time_windows": [
[
46800,
57600
]
]
},
{
"id": 6,
"location": [
106.6835,
10.7925
],
"service": 300,
"description": "Tiệm tạp hoá Gò Vấp",
"delivery": [
2
]
},
{
"id": 7,
"location": [
106.6961,
10.7826
],
"service": 600,
"description": "Nhà hàng Nguyễn Đình Chiểu",
"delivery": [
2
],
"time_windows": [
[
50400,
61200
]
]
},
{
"id": 8,
"location": [
106.7047,
10.7877
],
"service": 300,
"description": "Chung cư Bình Thạnh",
"delivery": [
1
]
}
],
"vehicles": [
{
"id": 1,
"description": "Xe tải nhỏ 1",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
12
]
},
{
"id": 2,
"description": "Xe tải nhỏ 2",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
12
]
},
{
"id": 3,
"description": "Xe giao hàng nhỏ",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
4
]
}
]
}'Replace YOUR_API_KEY with your API key before running.
// In production, read the key from an environment variable instead.
const API_KEY = "YOUR_API_KEY";
const params = new URLSearchParams([
["api-version", "1.1"],
["apikey", API_KEY],
]);
const body = {
"jobs": [
{
"id": 1,
"location": [
106.70592,
10.79628
],
"service": 600,
"description": "Cửa hàng Bình Thạnh",
"delivery": [
3
],
"time_windows": [
[
28800,
39600
]
]
},
{
"id": 2,
"location": [
106.7066,
10.80189
],
"service": 900,
"description": "Siêu thị mini Điện Biên Phủ",
"delivery": [
4
]
},
{
"id": 3,
"location": [
106.68982,
10.80159
],
"service": 600,
"description": "Quán ăn Phú Nhuận",
"delivery": [
2
],
"time_windows": [
[
32400,
43200
]
]
},
{
"id": 4,
"location": [
106.695,
10.785
],
"service": 300,
"description": "Nhà khách Quận 3",
"delivery": [
1
]
},
{
"id": 5,
"location": [
106.712,
10.7905
],
"service": 600,
"description": "Kho lẻ Thủ Đức",
"delivery": [
3
],
"time_windows": [
[
46800,
57600
]
]
},
{
"id": 6,
"location": [
106.6835,
10.7925
],
"service": 300,
"description": "Tiệm tạp hoá Gò Vấp",
"delivery": [
2
]
},
{
"id": 7,
"location": [
106.6961,
10.7826
],
"service": 600,
"description": "Nhà hàng Nguyễn Đình Chiểu",
"delivery": [
2
],
"time_windows": [
[
50400,
61200
]
]
},
{
"id": 8,
"location": [
106.7047,
10.7877
],
"service": 300,
"description": "Chung cư Bình Thạnh",
"delivery": [
1
]
}
],
"vehicles": [
{
"id": 1,
"description": "Xe tải nhỏ 1",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
12
]
},
{
"id": 2,
"description": "Xe tải nhỏ 2",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
12
]
},
{
"id": 3,
"description": "Xe giao hàng nhỏ",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
4
]
}
]
};
const response = await fetch(`https://maps.vietmap.vn/api/vrp?${params}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error(`Vietmap ${response.status}: ${await response.text()}`);
}
const data = await response.json();
console.log(data);Replace YOUR_API_KEY with your API key before running.
import requests
# In production, read the key from an environment variable instead.
API_KEY = "YOUR_API_KEY"
params = [
("api-version", "1.1"),
("apikey", API_KEY),
]
body = {
"jobs": [
{
"id": 1,
"location": [
106.70592,
10.79628,
],
"service": 600,
"description": "Cửa hàng Bình Thạnh",
"delivery": [
3,
],
"time_windows": [
[
28800,
39600,
],
],
},
{
"id": 2,
"location": [
106.7066,
10.80189,
],
"service": 900,
"description": "Siêu thị mini Điện Biên Phủ",
"delivery": [
4,
],
},
{
"id": 3,
"location": [
106.68982,
10.80159,
],
"service": 600,
"description": "Quán ăn Phú Nhuận",
"delivery": [
2,
],
"time_windows": [
[
32400,
43200,
],
],
},
{
"id": 4,
"location": [
106.695,
10.785,
],
"service": 300,
"description": "Nhà khách Quận 3",
"delivery": [
1,
],
},
{
"id": 5,
"location": [
106.712,
10.7905,
],
"service": 600,
"description": "Kho lẻ Thủ Đức",
"delivery": [
3,
],
"time_windows": [
[
46800,
57600,
],
],
},
{
"id": 6,
"location": [
106.6835,
10.7925,
],
"service": 300,
"description": "Tiệm tạp hoá Gò Vấp",
"delivery": [
2,
],
},
{
"id": 7,
"location": [
106.6961,
10.7826,
],
"service": 600,
"description": "Nhà hàng Nguyễn Đình Chiểu",
"delivery": [
2,
],
"time_windows": [
[
50400,
61200,
],
],
},
{
"id": 8,
"location": [
106.7047,
10.7877,
],
"service": 300,
"description": "Chung cư Bình Thạnh",
"delivery": [
1,
],
},
],
"vehicles": [
{
"id": 1,
"description": "Xe tải nhỏ 1",
"profile": "car",
"start": [
106.7,
10.79,
],
"end": [
106.7,
10.79,
],
"capacity": [
12,
],
},
{
"id": 2,
"description": "Xe tải nhỏ 2",
"profile": "car",
"start": [
106.7,
10.79,
],
"end": [
106.7,
10.79,
],
"capacity": [
12,
],
},
{
"id": 3,
"description": "Xe giao hàng nhỏ",
"profile": "car",
"start": [
106.7,
10.79,
],
"end": [
106.7,
10.79,
],
"capacity": [
4,
],
},
],
}
response = requests.post("https://maps.vietmap.vn/api/vrp", params=params, json=body, timeout=60)
response.raise_for_status()
print(response.json())Replace YOUR_API_KEY with your API key before running.
I need to integrate Vietmap's VRP API (api-version 1.1) into my application.
Official documentation: https://maps.vietmap.vn/docs/map-api/vrp/
Here is a sample request that works in the Vietmap API Playground:
POST https://maps.vietmap.vn/api/vrp?api-version=1.1&apikey=YOUR_API_KEY
Body (JSON):
```json
{
"jobs": [
{
"id": 1,
"location": [
106.70592,
10.79628
],
"service": 600,
"description": "Cửa hàng Bình Thạnh",
"delivery": [
3
],
"time_windows": [
[
28800,
39600
]
]
},
{
"id": 2,
"location": [
106.7066,
10.80189
],
"service": 900,
"description": "Siêu thị mini Điện Biên Phủ",
"delivery": [
4
]
},
{
"id": 3,
"location": [
106.68982,
10.80159
],
"service": 600,
"description": "Quán ăn Phú Nhuận",
"delivery": [
2
],
"time_windows": [
[
32400,
43200
]
]
},
{
"id": 4,
"location": [
106.695,
10.785
],
"service": 300,
"description": "Nhà khách Quận 3",
"delivery": [
1
]
},
{
"id": 5,
"location": [
106.712,
10.7905
],
"service": 600,
"description": "Kho lẻ Thủ Đức",
"delivery": [
3
],
"time_windows": [
[
46800,
57600
]
]
},
{
"id": 6,
"location": [
106.6835,
10.7925
],
"service": 300,
"description": "Tiệm tạp hoá Gò Vấp",
"delivery": [
2
]
},
{
"id": 7,
"location": [
106.6961,
10.7826
],
"service": 600,
"description": "Nhà hàng Nguyễn Đình Chiểu",
"delivery": [
2
],
"time_windows": [
[
50400,
61200
]
]
},
{
"id": 8,
"location": [
106.7047,
10.7877
],
"service": 300,
"description": "Chung cư Bình Thạnh",
"delivery": [
1
]
}
],
"vehicles": [
{
"id": 1,
"description": "Xe tải nhỏ 1",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
12
]
},
{
"id": 2,
"description": "Xe tải nhỏ 2",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
12
]
},
{
"id": 3,
"description": "Xe giao hàng nhỏ",
"profile": "car",
"start": [
106.7,
10.79
],
"end": [
106.7,
10.79
],
"capacity": [
4
]
}
]
}
```
Parameters in use:
- api-version = 1.1
Write code in [my language / framework] that calls this API, with these requirements:
1. Read the API key from the VIETMAP_API_KEY environment variable; never hard-code it.
2. Send the parameters in the query string exactly as in the sample; repeated parameters (such as `point`) must keep their order.
3. Handle Vietmap's HTTP errors:
- 401: the API key is wrong or revoked.
- 403: the key is restricted to a domain / IP that does not match.
- 423: the API is not enabled for the key's consumer, OR the account is out of credit — tell them apart by the response body ("exceeded credit" means out of credit).
- 429: rate limit exceeded — retry with increasing backoff.
4. Set a request timeout, and define types (type / interface / dataclass) for the response.
If unsure about a field name, look it up in the documentation linked above instead of guessing.Paste into ChatGPT, Claude… to generate integration code. The prompt never contains your API key.
https://tools.vietmap.vn/playground/en/vrp?sample=last-mileOpens the playground with exactly these parameters — for the docs or a colleague. The link never contains an API key.
What is the VRP API?
What is the VRP API?
The VRP API (vehicle routing) assigns many deliveries and pick-ups to many vehicles at once, respecting each vehicle’s capacity, customer time windows, vehicle skills (refrigerated, heavy trucks…) and priorities. It returns each vehicle’s route in driving order with arrival times and the load on board; anything that could not be placed is listed as unassigned, showing whether vehicles are short or constraints too tight.
What it is for
- Daily last-mile planning for a fleet.
- Deliveries within promised time slots.
- Pick up at A, deliver to B (shipments).
- Assigning field technicians by skill.
Sample request
POST https://maps.vietmap.vn/api/vrp?api-version=1.1&apikey=YOUR_API_KEY
body: { "vehicles": [ { "id": 1, "start": [lng, lat], "capacity": [12] } ], "jobs": [ { "id": 1, "location": [lng, lat], "delivery": [2] } ] }This page has 10 ready scenarios and Excel import/export to try real data.
VRP API FAQ
- What is VRP?
- VRP (the Vehicle Routing Problem) is splitting many deliveries and pick-ups across many vehicles and ordering each vehicle’s route for the lowest total cost, while respecting constraints such as capacity, time windows and vehicle skills. It is the core problem of last-mile delivery planning.
- Which constraints does the VRP API support?
- Vehicle capacity, customer time windows, vehicle skills, job priorities, and pick-up-and-delivery shipments collected at A and delivered to B.
- Why are some jobs listed as unassigned?
- They could not be placed on any vehicle under the current constraints — usually too few vehicles, more load than capacity, or time windows that are too tight. Add vehicles, widen the windows or raise capacity, then run again.
- Does it cost anything to try the VRP API?
- The playground comes with a demo API key, so you can call the VRP API straight from the browser without signing up. To build it into a product, register a VIETMAP account for your own key. Usage is billed per transaction, each API converting requests to transactions at its own rate; the pricing page has the details and the free trial.