Getting Started with MTA Bustime Information

To get started, first you need to get an API Key from the MTA Website. Fill out the form and you'll get an email with your key.

The API has vehicle information and stop information. You can see a full list of parameters on the website, but the important ones you'll probably want to use are:

  • key: Your API key. You need to send this.
  • VehicleRef: This is the 4 digit number you see on the side of the bus. Why you'd care about an individual bus is beyond me. You're probably more interested in...
  • LineRef: An actual route ID. Formatted like MTA NYCT_B63.
  • Direction: Buses go in two directions, so this is either 1 or 0.

Line Monitoring: Shows all the buses in a line, their location, bearing, direction they progressing along the line, status and information for the next stop they will come to.

Stop Monitoring: Shows a single stop, including how far away the next bus is in distance and number of stops. For Stop Monitoring you have to pass along a MonitoringRef, which is the ID for a particular stop.

At this point, you're probably wondering where you can find all these wonderful ids that are required as parameters. Luckily the MTA has them available as text file downloads.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var url = "http://bustime.mta.info/api/siri/stop-monitoring.json"
var data = {
    key: 'GET_YOUR_OWN_KEY', // see above for link
    LineRef: "MTA NYCT_B63",
    MonitoringRef: "MTA_305408"
};

// tells us how far away the bus is

$.ajax({
    url: url,
    data: data,
    dataType: 'jsonp', 
    success: function(result) {
        alert(result
            .Siri
            .ServiceDelivery
            .StopMonitoringDelivery[0]
            .MonitoredStopVisit[0]
            .MonitoredVehicleJourney
            .MonitoredCall
            .Extensions
            .Distances
            .PresentableDistance);
    }
});

2013-09-26