Skip to content

Toll costs for trucks and containers

Tolls depend on the vehicle class. In the Route v4 example, the Km 479+200 station on the Diễn Châu – Bãi Vọt expressway has three prices, 59,000, 96,000 and 140,000 VND, depending on the class. Quoting freight or reconciling trip costs for trucks and containers therefore needs the right vehicle class and the exact stations the vehicle passes.

Route v4 returns tolls per station along the route, calculated for the vehicle in the request.

Calculate tolls with Route v4

Call Route v4 with an origin, a destination, the vehicle type (vehicle) and annotations=toll. With vehicle=truck, also send capacity, the gross vehicle weight in kilograms; it is required for trucks. With vehicle=container, you can also send container_feet, the container length in feet. The other types are car and motorcycle.

https://maps.vietmap.vn/api/route/v4?apikey={your-apikey}&point=18.7338,105.6209&point=17.75697,106.12351&vehicle=truck&capacity=2000&annotations=toll

Each route in paths gains two fields:

"toll_cost": 59000,
"tolls": [
  {
    "id": 528,
    "name": "Trạm Thu Phí Nút Giao Quốc Lộ 46B",
    "address": "Cao Tốc Diễn Châu Bãi Vọt",
    "type": "entry",
    "price": 0
  },
  {
    "id": 544,
    "name": "Trạm Thu Phí Km 479+200",
    "address": "Cao Tốc Diễn Châu Bãi Vọt",
    "type": "exit",
    "price": 59000,
    "prices": { "523": 140000, "524": 96000, "528": 59000 }
  }
]
  • toll_cost: total toll for the route in VND, for the vehicle you sent.
  • tolls: the stations on the route. type is entry where the vehicle enters and exit where it leaves and pays. price is the charge for the vehicle you sent; prices lists the charge per vehicle class, when available.

Recommendations:

  • Calculate tolls leg by leg. Send 2 point values per call. For a multi-stop trip, call each leg and add up toll_cost.
  • Send the departure time in time (ISO-8601, UTC), for example time=2025-08-01T12:01:00Z, so Route v4 avoids zones restricted for your vehicle.
  • A 2-point request costs 1 transaction. The full formula is in How Pricing Works.

Example: tolls for a trip

The code below calculates tolls for a truck with a gross weight of 15 tons, adding up each leg of the trip.

// Node.js 18+. Call from your server so the API key stays private.
const KEY = process.env.VIETMAP_API_KEY;

// Toll cost of one leg. from, to: "lat,lng"
async function legTolls(from, to) {
  const params = new URLSearchParams([
    ["apikey", KEY],
    ["point", from],
    ["point", to],
    ["vehicle", "truck"],
    ["capacity", "15000"],
    ["annotations", "toll"],
  ]);
  const res = await fetch(`https://maps.vietmap.vn/api/route/v4?${params}`);
  if (!res.ok) throw new Error(`Route v4: HTTP ${res.status}`);
  const data = await res.json();
  if (data.code !== "OK") throw new Error(`Route v4: ${data.code}`);
  const path = data.paths[0];
  return { total: path.toll_cost ?? 0, stations: path.tolls ?? [] };
}

// Toll cost of a trip: the sum of its legs. points: ["lat,lng", ...]
async function tripTolls(points) {
  const legs = [];
  for (let i = 0; i + 1 < points.length; i++) {
    legs.push(await legTolls(points[i], points[i + 1]));
  }
  return {
    total: legs.reduce((sum, leg) => sum + leg.total, 0),
    stations: legs.flatMap((leg) => leg.stations),
  };
}

const trip = await tripTolls(["18.7338,105.6209", "17.75697,106.12351"]);
console.log("Total toll:", trip.total, "VND");
import os

import requests

KEY = os.environ["VIETMAP_API_KEY"]


def leg_tolls(origin, destination):
    """Toll cost of one leg. origin, destination: "lat,lng"."""
    params = [
        ("apikey", KEY),
        ("point", origin),
        ("point", destination),
        ("vehicle", "truck"),
        ("capacity", "15000"),
        ("annotations", "toll"),
    ]
    resp = requests.get("https://maps.vietmap.vn/api/route/v4", params=params, timeout=30)
    resp.raise_for_status()
    data = resp.json()
    if data["code"] != "OK":
        raise RuntimeError(f"Route v4: {data['code']}")
    path = data["paths"][0]
    return path.get("toll_cost", 0), path.get("tolls", [])


def trip_tolls(points):
    """Toll cost of a trip: the sum of its legs. points: ["lat,lng", ...]."""
    legs = [leg_tolls(a, b) for a, b in zip(points, points[1:])]
    return sum(total for total, _ in legs), [s for _, stations in legs for s in stations]


total, stations = trip_tolls(["18.7338,105.6209", "17.75697,106.12351"])
print("Total toll:", total, "VND")
Integrate VIETMAP toll costs into my project with Route v4, for trucks and containers.

GET https://maps.vietmap.vn/api/route/v4
  point=18.7338,105.6209
  point=17.75697,106.12351
  vehicle=truck
  capacity=15000
  annotations=toll
Read paths[0].toll_cost (total, VND) and paths[0].tolls (per station).

Requirements:
- Call the API from the server. Read the API key from the VIETMAP_API_KEY environment variable and send it as `apikey`; never hard-code it.
- Write a function that takes an origin and a destination, checks the HTTP status and returns the total and the list of stations.
- Send 2 point values per call; for a multi-stop trip, call each leg and add the results.
- Read the docs below first. Use only parameters and response fields documented there.

Docs:
- https://maps.vietmap.vn/docs/map-api/toll-cost/index.txt
- https://maps.vietmap.vn/docs/map-api/route-version/route-v4/index.txt
- https://maps.vietmap.vn/docs/assets/agents/routing.txt
  • Truck and container routing — routes by weight that avoid restricted roads.
  • Route v4 — every parameter and the response format.
  • VRP — split orders across a fleet before pricing each route.
Hotline
Tổng đài hỗ trợ
089.616.4567
Messenger Chat Facebook zalo Chat Zalo