How to optimize the route
You can optimize the route to reduce costs, distance, and the time taken and more.
- NodeJS
const fetch = require("node-fetch")
fetch("https://backend.impargo.eu/", {
method: "POST",
headers: {
"authorization": token,
"content-type": "application/json",
},
body: JSON.stringify([{
"operationName": "Optimize",
"variables": {
"stops": [
{"lat": 43.34991, "lon": 1.86602},
{"lat": 53.52996, "lon": -8.77419},
{"lat": 48.13641, "lon": 11.57754}
],
"fixLastStop": false,
"departureDate": null
},
"query": `query Optimize($stops: [OptimizationStop]!, $fixLastStop: Boolean, $departureDate: DateTime) {
optimize(
stops: $stops
fixLastStop: $fixLastStop
departureDate: $departureDate
) {
order
warning
__typename
}
}`
}])
})
.then(response => response.json())
.then(data => {
const graphqlData = data[0].data.optimize;
console.log("GraphQL Response:", graphqlData);
})
.catch(error => {
console.error("Fetch Error:", error);
});
- Response
[
{
"data": {
"optimize": {
"order": [
0,
1,
2
],
"warning": null,
"__typename": "OptimizationResult"
}
}
}
]