TSP API Playground

    Single-vehicle route optimisation (TSP)

    Given a list of stops, TSP reorders them into the shortest possible route. Unlike the Route API, which follows the order you type, TSP decides the order for you.

    The problem: one courier, six stops

    A depot and five drop-offs, entered in the order the orders arrived — that is, scattered. TSP reorders the visits so the total distance is the shortest, for one vehicle.

    • Route delivery: a courier picks up six scattered orders; TSP returns the visiting order instead of driving them as they came in.
    • Measurable benefit: this page also routes the original order through the Route API and draws both, so the gap is visible in km and minutes.
    • The API takes a list of points and returns points_order — the visiting order. With roundtrip off, the run ends at the last stop instead of returning to the depot.

    Click the map to add a point. The number on each marker matches the list on the left; the green chip below is its position in the optimised order.

    Code samples

    Example with sample parameters — fill in the form to get code for your own request.

    curl 'https://maps.vietmap.vn/api/tsp/v4?apikey=YOUR_API_KEY&point=10.7768,106.7009&point=10.80189,106.7066&point=10.7725,106.6828&point=10.80159,106.68982&point=10.7839,106.6911&point=10.79628,106.70592&points_encoded=false&vehicle=car&roundtrip=false&sources=first&destinations=any'

    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([
      ["apikey", API_KEY],
      ["point", "10.7768,106.7009"],
      ["point", "10.80189,106.7066"],
      ["point", "10.7725,106.6828"],
      ["point", "10.80159,106.68982"],
      ["point", "10.7839,106.6911"],
      ["point", "10.79628,106.70592"],
      ["points_encoded", "false"],
      ["vehicle", "car"],
      ["roundtrip", "false"],
      ["sources", "first"],
      ["destinations", "any"],
    ]);
    
    const response = await fetch(`https://maps.vietmap.vn/api/tsp/v4?${params}`);
    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 = [
        ("apikey", API_KEY),
        ("point", "10.7768,106.7009"),
        ("point", "10.80189,106.7066"),
        ("point", "10.7725,106.6828"),
        ("point", "10.80159,106.68982"),
        ("point", "10.7839,106.6911"),
        ("point", "10.79628,106.70592"),
        ("points_encoded", "false"),
        ("vehicle", "car"),
        ("roundtrip", "false"),
        ("sources", "first"),
        ("destinations", "any"),
    ]
    
    response = requests.get("https://maps.vietmap.vn/api/tsp/v4", params=params, timeout=30)
    response.raise_for_status()
    print(response.json())

    Replace YOUR_API_KEY with your API key before running.

    https://maps.vietmap.vn/api/tsp/v4?apikey=YOUR_API_KEY&point=10.7768,106.7009&point=10.80189,106.7066&point=10.7725,106.6828&point=10.80159,106.68982&point=10.7839,106.6911&point=10.79628,106.70592&points_encoded=false&vehicle=car&roundtrip=false&sources=first&destinations=any

    Replace YOUR_API_KEY with your API key before running.

    I need to integrate Vietmap's TSP API v4 into my application.
    
    Official documentation: https://maps.vietmap.vn/docs/map-api/tsp-version/tsp-v4/
    
    Here is a sample request that works in the Vietmap API Playground:
    
    GET https://maps.vietmap.vn/api/tsp/v4?apikey=YOUR_API_KEY&point=10.7768,106.7009&point=10.80189,106.7066&point=10.7725,106.6828&point=10.80159,106.68982&point=10.7839,106.6911&point=10.79628,106.70592&points_encoded=false&vehicle=car&roundtrip=false&sources=first&destinations=any
    
    Parameters in use:
    - point = 10.7768,106.7009
    - point = 10.80189,106.7066
    - point = 10.7725,106.6828
    - point = 10.80159,106.68982
    - point = 10.7839,106.6911
    - point = 10.79628,106.70592
    - points_encoded = false
    - vehicle = car
    - roundtrip = false
    - sources = first
    - destinations = any
    
    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.

    What is the TSP API?

    The TSP API (travelling salesman) reorders a list of stops so the total distance is shortest, for one vehicle. The start and end can be fixed, or the route can return to the start; the result gives the optimal visiting order and the path. With several vehicles, capacities or time windows, use VRP.

    What it is for

    • Ordering one courier’s deliveries for the day.
    • Visit plans for field sales.
    • Collection or inspection rounds.
    • Multi-stop day trips.

    Sample request

    GET https://maps.vietmap.vn/api/tsp/v4?apikey=YOUR_API_KEY&point=10.7768,106.7009&point=10.8018,106.7066&point=10.7725,106.6828&vehicle=motorcycle&sources=first&points_encoded=false

    points_order in the response is the optimal visiting order of the points sent.

    TSP API FAQ

    What is TSP?
    TSP (the Travelling Salesman Problem) is finding the order to visit a list of stops with the shortest total distance. The TSP API solves it for one vehicle and returns the optimal order (points_order) with the path.
    How is TSP different from VRP?
    TSP is for one vehicle with no capacity or time-window constraints. With several vehicles, limited capacity or customers expecting delivery slots, use the VRP API.
    Can the start and end points be fixed?
    Yes. The start and end can be fixed, or the route can return to the start (back to the depot, say). This page lets you switch those options on and compare the route before and after optimising.
    Does it cost anything to try the TSP API?
    The playground comes with a demo API key, so you can call the TSP 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.