php - GTFS 实时 php

标签 php mysql real-time gtfs

我有一个带有 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/

相关文章:

python - 当cron带来新数据时如何正确更新webapp

PHP MYSQL 内连接到 JSON

mysql - 迭代 mysql 字段并更新字段

用于音频处理的 Java 实用吗?

c++ - 如何根据固定的循环频率正确协调线程?

php - 数据抓取/重组速度

php - 使用 .htaccess 文件创建用户友好的 URL

php - 在 LAMPP for Ubuntu 中将 PHP 从 5.5 升级到 5.6

php - 查询在 phpMyAdmin 中运行良好,但 0 导致 php 本身......?

mysql - GROUP 中的 MIN 日期