gpt4 book ai didi

php - GTFS 实时 php

转载 作者:可可西里 更新时间:2023-11-01 08:05:31 25 4
gpt4 key购买 nike

我有一个带有 GTFS 数据的 MySQL 数据库设置,我有返回停止时间的 php 脚本,我正在寻找添加实时数据。

我知道 Google 有关于如何将 gtfs realtime 与 php ( https://github.com/google/gtfs-realtime-bindings-php ) 一起使用的说明,但我似乎无法弄清楚如何让它工作。

我想做的是(使用所需的任何信息:trip_id、stop_id 等)返回 trip_update 延迟值,以便我可以相应地更新停止时间。

有人知道好的教程吗?或者有人可以帮我弄清楚该怎么做吗?

最佳答案

一个更完整的 GTFS 实时 PHP 示例可能如下所示:

foreach ($feed->getEntityList() as $entity) {
if ($entity->hasTripUpdate()) {
$trip = $entity->getTripUpdate();
error_log("trip id: " . $trip->getTrip()->getTripId());
foreach ($trip->getStopTimeUpdateList() as $stu) {
if ($stu->hasArrival()) {
$ste = $stu->getArrival();
error_log(" arrival delay: " . $ste->getDelay());
error_log(" arrival time: " . $ste->getTime());
}
if ($stu->hasDeparture()) {
$ste = $stu->getDeparture();
error_log(" departure delay: " . $ste->getDelay());
error_log(" departure time: " . $ste->getTime());
}
}
}
}

注意方法名称如何对应于底层 GTFS 实时模式中的字段:

https://developers.google.com/transit/gtfs-realtime/gtfs-realtime-proto

您可以在以下位置查看从架构生成的 PHP 源代码:

https://github.com/google/gtfs-realtime-bindings-php/blob/master/src/gtfs-realtime.php

关于php - GTFS 实时 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30008632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com