Skip to content

Commit

Permalink
Merge pull request #3 from mapup/refactor-scripts
Browse files Browse the repository at this point in the history
change in comment statements
  • Loading branch information
ajay-padwal-mapup authored Mar 12, 2024
2 parents 54b1c9c + a9249df commit 571e3d5
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions javascript/route_encoded_polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit 571e3d5

Please sign in to comment.