Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src Update bindings to Feb 20th 2019 gtfs-realtime.proto (#43) Apr 22, 2019
.gitignore Initial commit for Java bindings. Jan 7, 2015
README.md
UPDATING.md Update Java release docs Jun 17, 2019
pom.xml

README.md

Java GTFS-realtime Language Bindings

Maven Central Version

Provides Java classes generated from the GTFS-realtime Protocol Buffer specification. These classes will allow you to parse a binary Protocol Buffer GTFS-realtime data feed into Java objects.

Add the Dependency

To use the gtfs-realtime-bindings classes in your own project, you need to add an appropriate dependency. We publish our module to the Maven Central Repository so that it can be easily referenced by Java build tools like Maven, Ivy, and Gradle.

For Maven, add the following to your pom.xml dependencies section:

<dependency>
  <groupId>io.mobilitydata.transit</groupId>
  <artifactId>gtfs-realtime-bindings</artifactId>
  <version>0.0.5</version>
</dependency>

For Gradle, add the following to your build.gradle dependecies section:

compile group: 'io.mobilitydata.transit', name: 'gtfs-realtime-bindings', version: '0.0.5'

Make sure the Maven central repository is referenced by your project.

Example Code

The following code snippet demonstrates downloading a GTFS-realtime data feed from a particular URL, parsing it as a FeedMessage (the root type of the GTFS-realtime schema), and iterating over the results.

import java.net.URL;

import com.google.transit.realtime.GtfsRealtime.FeedEntity;
import com.google.transit.realtime.GtfsRealtime.FeedMessage;

public class GtfsRealtimeExample {
  public static void main(String[] args) throws Exception {
    URL url = new URL("URL OF YOUR GTFS-REALTIME SOURCE GOES HERE");
    FeedMessage feed = FeedMessage.parseFrom(url.openStream());
    for (FeedEntity entity : feed.getEntityList()) {
      if (entity.hasTripUpdate()) {
        System.out.println(entity.getTripUpdate());
      }
    }
  }
}

For more details on the naming conventions for the Java classes generated from the gtfs-realtime.proto, check out the Java Generated Code section of the Protocol Buffers developer site.

You can’t perform that action at this time.