Skip to content

Instantly share code, notes, and snippets.

@vramirez122000
Created July 8, 2015 00:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vramirez122000/06abc6e72ceeec660239 to your computer and use it in GitHub Desktop.
Save vramirez122000/06abc6e72ceeec660239 to your computer and use it in GitHub Desktop.
GTFS Realtime Example Java
import com.google.transit.realtime.GtfsRealtime;
import static com.google.transit.realtime.GtfsRealtime.*;
/**
* Created by victor on 2/07/15.
*/
public class EndpointMain {
public static void main(String[] args) throws Exception {
VehiclePosition vehPosition = VehiclePosition.newBuilder()
.setPosition(
Position.newBuilder()
.setLatitude(18)
.setLongitude(-66).build())
.build();
FeedMessage.Builder feedBuilder = FeedMessage.newBuilder()
.setHeader(FeedHeader.newBuilder().setGtfsRealtimeVersion("1"))
.addEntity(FeedEntity.newBuilder().setId("1").setVehicle(vehPosition));
if(!feedBuilder.isInitialized()) {
System.err.print("error");
};
FeedMessage msg = feedBuilder.build();
msg.writeTo(System.out);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment