diff --git a/javascript/route_encoded_polyline.js b/javascript/route_encoded_polyline.js index 42702af..46e8cc3 100644 --- a/javascript/route_encoded_polyline.js +++ b/javascript/route_encoded_polyline.js @@ -2,65 +2,69 @@ const TOLLGURU_API_KEY = process.env.TOLLGURU_API_KEY; const TOLLGURU_API_URL = "https://apis.tollguru.com/toll/v2"; const POLYLINE_ENDPOINT = "complete-polyline-from-mapping-service"; -const polyline = "gib}FjbyeO...a@?c@?c@@g@"; // replace with your own polyline -const path = "43.64183,-79.38246|18.63085,-100.12845"; // replace with your own path +const polyline = "gib}FjbyeO...a@?c@?c@@g@"; // replace with your own polyline +const path = "43.64183,-79.38246|18.63085,-100.12845"; // replace with your own path function routeEncodedPolyline() { - const url = `${TOLLGURU_API_URL}/${POLYLINE_ENDPOINT}`; + const url = `${TOLLGURU_API_URL}/${POLYLINE_ENDPOINT}`; - const payload = JSON.stringify({ - source: "here", - polyline, - height: 10, // optional parameters - weight: 30000, // optional parameters - vehicleType: "2AxlesTruck", // if not set, by default it will set vehicleType as 2AxlesAuto - departure_time: 1609507347, // optional parameters - }); + const payload = JSON.stringify({ + source: "here", + polyline, - const headers = { - 'x-api-key': TOLLGURU_API_KEY, - 'Content-Type': 'application/json' - }; + // Optional parameters... + vehicleType: "2AxlesTruck", // if not set, by default it will set vehicleType as 2AxlesAuto + height: 10, + weight: 30000, + departure_time: 1609507347, + }); - return fetch(url, { - method: 'POST', - headers: headers, - body: payload - }); + const headers = { + "x-api-key": TOLLGURU_API_KEY, + "Content-Type": "application/json", + }; + + return fetch(url, { + method: "POST", + headers: headers, + body: payload, + }); } function routePathLatLng() { - const url = `${TOLLGURU_API_URL}/${POLYLINE_ENDPOINT}`; + const url = `${TOLLGURU_API_URL}/${POLYLINE_ENDPOINT}`; + + const payload = JSON.stringify({ + source: "here", + path, - const payload = JSON.stringify({ - source: "here", - path, - height: 10, // optional parameters - weight: 30000, // optional parameters - vehicleType: "2AxlesTruck", // if not set, by default it will set vehicleType as 2AxlesAuto - departure_time: 1609507347, // optional parameters - }); + // Optional parameters... + height: 10, + weight: 30000, + vehicleType: "2AxlesTruck", // if not set, by default it will set vehicleType as 2AxlesAuto + departure_time: 1609507347, + }); - const headers = { - 'x-api-key': TOLLGURU_API_KEY, - 'Content-Type': 'application/json' - }; + const headers = { + "x-api-key": TOLLGURU_API_KEY, + "Content-Type": "application/json", + }; - return fetch(url, { - method: 'POST', - headers: headers, - body: payload - }); + return fetch(url, { + method: "POST", + headers: headers, + body: payload, + }); } // Example usage: routeEncodedPolyline() - .then(response => response.json()) - .then(data => console.log(data)) - .catch(error => console.error('Error:', error)); + .then((response) => response.json()) + .then((data) => console.log(data)) + .catch((error) => console.error("Error:", error)); // Uncomment the following lines to test routePathLatLng() routePathLatLng() - .then(response => response.json()) - .then(data => console.log(data)) - .catch(error => console.error('Error:', error)); + .then((response) => response.json()) + .then((data) => console.log(data)) + .catch((error) => console.error("Error:", error));