-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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 | ||
|
||
function routeEncodedPolyline() { | ||
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 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 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 | ||
}); | ||
|
||
const headers = { | ||
'x-api-key': TOLLGURU_API_KEY, | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
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)); | ||
|
||
// Uncomment the following lines to test routePathLatLng() | ||
routePathLatLng() | ||
.then(response => response.json()) | ||
.then(data => console.log(data)) | ||
.catch(error => console.error('Error:', error)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
define('TOLLGURU_API_KEY', getenv('TOLLGURU_API_KEY')); | ||
define('TOLLGURU_API_URL', 'https://apis.tollguru.com/toll/v2'); | ||
define('POLYLINE_ENDPOINT', 'complete-polyline-from-mapping-service'); | ||
|
||
$polyline = 'gib}FjbyeO...a@?c@?c@@g@'; // replace with your own polyline | ||
$path = "43.64183,-79.38246|18.63085,-100.12845"; // replace with your own path | ||
|
||
function routeEncodedPolyline() { | ||
global $polyline; | ||
|
||
$url = TOLLGURU_API_URL . '/' . POLYLINE_ENDPOINT; | ||
|
||
$payload = json_encode([ | ||
'source' => 'here', | ||
'polyline' => $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 | ||
]); | ||
|
||
$headers = [ | ||
'x-api-key: ' . TOLLGURU_API_KEY, | ||
'Content-Type: application/json', | ||
]; | ||
|
||
$options = [ | ||
'http' => [ | ||
'method' => 'POST', | ||
'header' => implode("\r\n", $headers), | ||
'content' => $payload, | ||
], | ||
]; | ||
|
||
$context = stream_context_create($options); | ||
return file_get_contents($url, false, $context); | ||
} | ||
|
||
function routePathLatLng() { | ||
global $path; | ||
|
||
$url = TOLLGURU_API_URL . '/' . POLYLINE_ENDPOINT; | ||
|
||
$payload = json_encode([ | ||
'source' => 'here', | ||
'path' => $path, // replace with your own 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 | ||
]); | ||
|
||
$headers = [ | ||
'x-api-key: ' . TOLLGURU_API_KEY, | ||
'Content-Type: application/json', | ||
]; | ||
|
||
$options = [ | ||
'http' => [ | ||
'method' => 'POST', | ||
'header' => implode("\r\n", $headers), | ||
'content' => $payload, | ||
], | ||
]; | ||
|
||
$context = stream_context_create($options); | ||
return file_get_contents($url, false, $context); | ||
} | ||
|
||
// Example usage: | ||
$response1 = routeEncodedPolyline(); | ||
$data1 = json_decode($response1, true); | ||
print_r($data1); | ||
|
||
// Uncomment the following lines to test routePathLatLng() | ||
$response2 = routePathLatLng(); | ||
$data2 = json_decode($response2, true); | ||
print_r($data2); | ||
|
||
?> |