You're viewing the legacy docs. They are deprecated as of May 18, 2016.
Go to current docs

Firebase Open Data Sets

Transit Open Data Sets

Get up-to-the-minute location data on public transit vehicles from 50+ cities and college campuses across North America.

Firebase Open Data Sets are deprecated and will be shut down on March 30th, 2016.

Overview

You can view the realtime transit data in the App Dashboard.

Live Example

We've used this open data set to create a realtime map of Transit systems which can be seen below.

Select a transit system:

View source of this map.

Data Structure

The transit data is seperated by transit system. Each transit system has a list of routes and a list of vehicles. Each route has a list of vehicles currently on that route and vehicles contains specific information about that vehicle's location.

{
    $transitSystem: {
        routes: {
            $route: {                   // A list of vehicles on this route
                $vehicleId: true        // A vehicle ID
            }
        },
        vehicles: {
            $vehicleId: {
                heading: Number,        // Direction the bus is heading
                id: String,             // Vehicle ID
                lat: Number,            // Vehicle latitude
                lon: Number,            // Vehicle longitude
                routeTag: String,       // Current route
                timestamp: Number,      // Last updated
                vtype: String           // Vehicle type (i.e. "bus")
            }
        }
    }
}

Example Code

Get the location of every bus along a specific route:

var transitLine = 'X';
var transitRef = new Firebase('https://publicdata-transit.firebaseio.com/sf_muni');
var lineIndex = transitRef.child('index').child(transitLine);

lineIndex.on('child_added', function(snapshot) {
    var id = snapshot.key();
    transitRef.child('data').child(id).on('value', busUpdated);
});
lineIndex.on('child_removed', function(snapshot) {
    var id = snapshot.key();
    transitRef.child('data').child(id).off('value', busUpdated);
});

function busUpdated(snapshot) {
    // Bus line 'X' changed location.
    var info = snapshot.val();
    // Retrieve latitude/longitude with info.lat/info.lon.
}

Data Source

Data is provided via NextBus and CTABusTracker.