到目前为止,我已经填写了开发人员 API 密钥的MTA 在线注册表单。然后在我的 android 项目中,我从Google 的 github 存储库之一实现了 gtfs 实时绑定依赖,
compile group: 'com.google.transit', name: 'gtfs-realtime-bindings', version: '0.0.4'
使用他们的 Java 类,我尝试使用以下代码从 MTA 提供的链接中打印出所有 gtfs 数据,
try {
String urlString = "http://datamine.mta.info/mta_esi.php?key=insertmykeyhere";
URL url = new URL(urlString.toString());
GtfsRealtime.FeedMessage feed = GtfsRealtime.FeedMessage.parseFrom(url.openStream());
for (GtfsRealtime.FeedEntity entity : feed.getEntityList()) {
if (entity.hasTripUpdate()) {
Log.d("stuff", entity.getTripUpdate().toString());
}
}
} catch (IOException e) {
e.printStackTrace();
}
但是,我现在无法解释打印出来的数据。我知道有来自http://web.mta.info/developers/developer-data-terms.html的静态数据馈送,我用它来解释一些数据。这是打印出来的旅行更新之一,
stuff: trip {
trip_id: "036000_GS.N01R"
start_date: "20170218"
route_id: "GS"
1001: "\n\0200S 0600 GCS/TSS\020\001\030\001"
}
stop_time_update {
departure {
time: 1487415600
}
stop_id: "901N"
1001: "\n\0011\022\0011"
}
stop_time_update {
arrival {
time: 1487415690
}
stop_id: "902N"
1001: "\n\0011"
}
我了解trip_id、start_date 和stop_id 等部分内容。但是诸如 trip_id、time 和 1001 之类的部分我仍然不确定,静态提要中的文本文件并不能很好地解释它们。