⚠️ The MTA API Terms and Conditions prohibits developers from giving users direct access to MTA servers. Any realtime data that is retrieved in this library must be served to users on your own servers.
OneMTA is a Java wrapper for the MTA SIRI REST API and MTA Realtime GTFS API.
OneMTA requires at least Java 8.
OneMTA also requires the protobuf-java library to be installed. Make sure you are using the same version as specified in the pom.xml file.
Compiled binaries can be installed from:
OneMTA requires static data from the MTA for most route and stop information. Latest static data for the MTA is available at http://web.mta.info/developers/developer-data-terms.html#data.
Static data is only required for the endpoints you are using. For busses all boroughs are required, along with bus company.
MTA mta = MTA.create( busToken, subwayToken, DataResource.create(DataResourceType.Bus_Bronx, new File("google_transit_bronx.zip")), DataResource.create(DataResourceType.Bus_Brooklyn, new File("google_transit_brooklyn.zip")), DataResource.create(DataResourceType.Bus_Manhattan, new File("google_transit_manhattan.zip")), DataResource.create(DataResourceType.Bus_Queens, new File("google_transit_queens.zip")), DataResource.create(DataResourceType.Bus_StatenIsland, new File("google_transit_staten_island.zip")), DataResource.create(DataResourceType.Bus_Company, new File("google_transit_bus_company.zip")), DataResource.create(DataResourceType.Subway, new File("google_transit_subway.zip")), DataResource.create(DataResourceType.LongIslandRailroad, new File("google_transit_lirr.zip")), DataResource.create(DataResourceType.MetroNorthRailroad, new File("google_transit_mnr.zip")) );
Retrieve routes along with alerts and vehicles on the route.
Bus.Route M1 = mta.getBusRoute("M1", DataResourceType.Bus_Manhattan); Subway.Route SI = mta.getSubwayRoute("SI"); LIRR.Route PW = mta.getLIRRRoute(9); MNR.Route HM = mta.getMNRRoute(2);
Retrieve stops with alerts and vehicles en route.
Bus.Stop stop = mta.getBusStop(400561); Subway.Stop GCT = mta.getSubwayStop("631"); LIRR.Stop FLS = mta.getLIRRStop("FLS"); MNR.Stop WLN = mta.getMNRStop("1WN");
Retrieve live vehicle information from stops and routes.
Bus.Vehicle busses = stop.getVehicles(); Subway.Vehicle subways = SI.getVehicles(); LIRR.Vehicle lirr = PW.getVehicles(); MNR.Vehicle mnr = WLN.getVehicles();
Retrieve alerts for all stops and routes.
Bus.Alert busAlerts = mta.getBusAlerts(); Subway.Alert subwayAlerts = SI.getAlerts(); LIRR.Alert lirrAlerts = FLS.getAlerts(); MNR.Alert mnrAlerts = mta.getMNRAlerts();
Sample response data available on the
Install protobuf and gtfs realtime proto manually
For local tests you can use Java 8+, however only methods in the Java 8 API may be used. The
src/main/java9 folder should not be marked as a source root.
bus.txtthat contains the bus token in the
subway.txtthat contains the subway in the
Devs running remote tests through GitHub Actions may do so by running the
MTA CI workflow manually in the actions tab of your fork. Note that this requires two secrets, a
BUS_TOKEN which contains the bus token, and a
SUBWAY_TOKEN which contains the subway token.
This library is released under the GNU General Public License (GPL) v2.0.
By using the MTA API you are subject to their Terms and Conditions.
In developing your app, you will provide that the MTA data feed is available to others only from a non-MTA server. Accordingly, you will download and store the MTA data feed on a non-MTA server which users of your App will access in order to obtain data. MTA prohibits the development of an app that would make the data available to others directly from MTA’s server(s).
In order to create applications and systems dependent on the MTA API, this library was created to simply the usage of the MTA Bus REST API and the MTA Subway Realtime GTFS API. Condenses these two poorly documented APIs into a singular, well documented Java library.