Vietmap Matrix API Playground

    Matrix API

    Calculate distance matrix between multiple points, suitable for logistics and delivery applications (find nearest driver, find shortest/fastest route between multiple points).

    Code samples

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

    curl 'https://maps.vietmap.vn/api/matrix/v4?apikey=YOUR_API_KEY&point=10.776889,106.700806&point=10.818,106.6585&points_encoded=true&vehicle=car&sources=all&destinations=all&annotation=duration'

    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.776889,106.700806"],
      ["point", "10.818,106.6585"],
      ["points_encoded", "true"],
      ["vehicle", "car"],
      ["sources", "all"],
      ["destinations", "all"],
      ["annotation", "duration"],
    ]);
    
    const response = await fetch(`https://maps.vietmap.vn/api/matrix/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.776889,106.700806"),
        ("point", "10.818,106.6585"),
        ("points_encoded", "true"),
        ("vehicle", "car"),
        ("sources", "all"),
        ("destinations", "all"),
        ("annotation", "duration"),
    ]
    
    response = requests.get("https://maps.vietmap.vn/api/matrix/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/matrix/v4?apikey=YOUR_API_KEY&point=10.776889,106.700806&point=10.818,106.6585&points_encoded=true&vehicle=car&sources=all&destinations=all&annotation=duration

    Replace YOUR_API_KEY with your API key before running.

    I need to integrate Vietmap's Matrix API v4 into my application.
    
    Official documentation: https://maps.vietmap.vn/docs/map-api/matrix-version/matrix-v4/
    
    Here is a sample request that works in the Vietmap API Playground:
    
    GET https://maps.vietmap.vn/api/matrix/v4?apikey=YOUR_API_KEY&point=10.776889,106.700806&point=10.818,106.6585&points_encoded=true&vehicle=car&sources=all&destinations=all&annotation=duration
    
    Parameters in use:
    - point = 10.776889,106.700806
    - point = 10.818,106.6585
    - points_encoded = true
    - vehicle = car
    - sources = all
    - destinations = all
    - annotation = duration
    
    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 Distance Matrix API?

    The Matrix API (Distance Matrix API) computes travel time and distance between many origins and many destinations in a single call, instead of one Route call per pair. Sources and destinations can be listed separately so only the pairs needed are computed. The result feeds dispatch decisions: the nearest driver for a customer, the depot to serve each order, or input for your own optimiser.

    What it is for

    • Finding the nearest driver in a ride-hailing app.
    • Choosing the depot that serves each order.
    • Filtering stores within a travel-time budget.
    • Input for an in-house routing algorithm.

    Sample request

    GET https://maps.vietmap.vn/api/matrix/v4?apikey=YOUR_API_KEY&point=10.7768,106.7009&point=10.8018,106.7066&point=10.7725,106.6828&sources=0&destinations=1;2&annotation=duration,distance

    sources and destinations are indexes (from 0) into the point list, joined by semicolons.

    Distance Matrix API FAQ

    What is a distance matrix API?
    A distance matrix is the table of travel time and distance between every origin and destination pair. The Matrix API computes the whole table in one call instead of one Route call per pair, along real roads rather than straight lines.
    When should I use Matrix rather than Route?
    Use Matrix when you only need the time and distance figures for many pairs, to compare or decide. Use Route when you need the actual path to draw and turn-by-turn instructions.
    How do I compute only some of the pairs?
    Use sources and destinations: list the indexes (from 0) of the origins and destinations within the point list, joined by semicolons. For one driver and three customers: sources=0, destinations=1;2;3.
    Does it cost anything to try the Distance Matrix API?
    The playground comes with a demo API key, so you can call the Distance Matrix 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.