'rapidJSON', 'coordOutputFormat' => 'EPSG:4326', 'mode' => 'direct', 'type_dm' => 'stop', 'name_dm' => $stop, 'depArrMacro' => 'dep', 'itdDate' => date('Ymd', $when), 'itdTime' => date('Hi', $when), 'TfNSWDM' => 'true' );
$url = $apiEndpoint . $apiCall . '?' . http_build_query($params);
// Create a stream
$opts = [
"http" => [
"method" => "GET",
"header" => "Authorization: apikey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\n"
]
];
// Perform the request and build the JSON response data
$context = stream_context_create($opts);
$response = file_get_contents($url, false, $context);
$json = json_decode($response, true);
$stopEvents = $json['stopEvents'];
// Loop over returned stop events
foreach ($stopEvents as $stopEvent) {
// Extract the route information
$transportation = $stopEvent['transportation'];
$routeNumber = $transportation['number'];
$destination = $transportation['destination']['name']; // In the case of a train, the location includes platform information
$location = $stopEvent['location']; // Determine how many minutes until departure
$time = strtotime($stopEvent['departureTimePlanned']);
$countdown = $time - time();
$minutes = round($countdown / 60); // Output the stop event with a countdown timer
echo $minutes . "m from " . $location['name'] . "\n
";
echo $routeNumber . " to " . $destination . "\n\n
";
}