Distance Matrix
curl --request POST \
--url https://b.hudhud.sa/v1/routing/matrix \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"coordinates": [
{
"lat": 24.7136,
"lon": 46.6753
}
],
"destinations": [
1
],
"sources": [
0
]
}
'import requests
url = "https://b.hudhud.sa/v1/routing/matrix"
payload = {
"coordinates": [
{
"lat": 24.7136,
"lon": 46.6753
}
],
"destinations": [1],
"sources": [0]
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({coordinates: [{lat: 24.7136, lon: 46.6753}], destinations: [1], sources: [0]})
};
fetch('https://b.hudhud.sa/v1/routing/matrix', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://b.hudhud.sa/v1/routing/matrix",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'coordinates' => [
[
'lat' => 24.7136,
'lon' => 46.6753
]
],
'destinations' => [
1
],
'sources' => [
0
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://b.hudhud.sa/v1/routing/matrix"
payload := strings.NewReader("{\n \"coordinates\": [\n {\n \"lat\": 24.7136,\n \"lon\": 46.6753\n }\n ],\n \"destinations\": [\n 1\n ],\n \"sources\": [\n 0\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://b.hudhud.sa/v1/routing/matrix")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"coordinates\": [\n {\n \"lat\": 24.7136,\n \"lon\": 46.6753\n }\n ],\n \"destinations\": [\n 1\n ],\n \"sources\": [\n 0\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://b.hudhud.sa/v1/routing/matrix")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"coordinates\": [\n {\n \"lat\": 24.7136,\n \"lon\": 46.6753\n }\n ],\n \"destinations\": [\n 1\n ],\n \"sources\": [\n 0\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": "",
"data": {
"destinations": [
{
"distance": 123,
"location": {
"lat": 24.7136,
"lon": 46.6753
}
}
],
"distances": [
[
123
]
],
"durations": [
[
123
]
],
"sources": [
{
"distance": 123,
"location": {
"lat": 24.7136,
"lon": 46.6753
}
}
]
},
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}Routing
Distance Matrix
Compute a matrix of travel distances and durations between multiple origins and destinations. Returns pairwise distance and duration values for route planning and optimization.
Retryable errors
Retry these errors with exponential backoff and jitter:
500,503, and504.429with the coderate_limit_exceeded. Wait the number of seconds in theRetry-Afterheader.
Do not retry other errors, which fail again unchanged. A 429 with the code daily_limit_exceeded succeeds after the limit resets at 00:00 UTC; one with trial_limit_reached does not succeed again.
POST
/
routing
/
matrix
Distance Matrix
curl --request POST \
--url https://b.hudhud.sa/v1/routing/matrix \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"coordinates": [
{
"lat": 24.7136,
"lon": 46.6753
}
],
"destinations": [
1
],
"sources": [
0
]
}
'import requests
url = "https://b.hudhud.sa/v1/routing/matrix"
payload = {
"coordinates": [
{
"lat": 24.7136,
"lon": 46.6753
}
],
"destinations": [1],
"sources": [0]
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({coordinates: [{lat: 24.7136, lon: 46.6753}], destinations: [1], sources: [0]})
};
fetch('https://b.hudhud.sa/v1/routing/matrix', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://b.hudhud.sa/v1/routing/matrix",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'coordinates' => [
[
'lat' => 24.7136,
'lon' => 46.6753
]
],
'destinations' => [
1
],
'sources' => [
0
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://b.hudhud.sa/v1/routing/matrix"
payload := strings.NewReader("{\n \"coordinates\": [\n {\n \"lat\": 24.7136,\n \"lon\": 46.6753\n }\n ],\n \"destinations\": [\n 1\n ],\n \"sources\": [\n 0\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://b.hudhud.sa/v1/routing/matrix")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"coordinates\": [\n {\n \"lat\": 24.7136,\n \"lon\": 46.6753\n }\n ],\n \"destinations\": [\n 1\n ],\n \"sources\": [\n 0\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://b.hudhud.sa/v1/routing/matrix")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"coordinates\": [\n {\n \"lat\": 24.7136,\n \"lon\": 46.6753\n }\n ],\n \"destinations\": [\n 1\n ],\n \"sources\": [\n 0\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": "",
"data": {
"destinations": [
{
"distance": 123,
"location": {
"lat": 24.7136,
"lon": 46.6753
}
}
],
"distances": [
[
123
]
],
"durations": [
[
123
]
],
"sources": [
{
"distance": 123,
"location": {
"lat": 24.7136,
"lon": 46.6753
}
}
]
},
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}{
"code": "",
"data": "<unknown>",
"error": "",
"ok": true
}Compute travel distances and durations between multiple origins and destinations at once.
Optimal Planning
The distance matrix is essential for logistics and dispatching. It allows you to quickly find the nearest driver or service point across the road network.Request Body
coordinates: A list of all unique points involved.sources: Indices into thecoordinateslist for start points.destinations: Indices into thecoordinateslist for end points.
Note on Large Requests
The maximum number of source-destination pairs in a single request is limited. Contact us if you need to perform high-volume computations.Authorizations
Body
application/json
Coordinates with source and destination indices
Coordinates with source and destination indices
