Metro’s Official Blog on Transit Data and Technology

Main menu

Metro Bus & Rail Real-time Arrivals Overview

Metro’s Realtime Application Programming Interface (API) lives at http://api.metro.net/. It gives you access to the positions of Metro vehicles on their routes in real time.

The Realtime API is a RESTful web service designed to serve bus location data gathered by our Advanced Transportation Management System (ATMS) and the new Nextrip prediction engine. This is the result of years of difficult work refining the information we collect from the GPS trackers on every bus. Sometimes that data arrives too late to give us useful information. Our busses serve 1433 square miles. Whenever the buses travel into a radio shadow we need to make a prediction about the location of the bus. This is where Nextrip comes into play.

Our Nextrip service is provided by NextBus, if you are familiar with their XML structure — you are welcome to retrieve the data from them.

You may now easily build and deploy custom applications using Metro’s data as a foundation. If you want to build a mobile application that plots the position of Metro’s Rapid busses on a map then this is the API for you. The interface gives your program access to collections and elements. Collections retrieve lists of element URIs. Element URIs retrieve a representation of the element. Only HTTP GET operations are allowed.

This new section of the site is here to document the interface and give you some examples of how you might use it. We need more examples! Please help us help you by including your code snippets in the comments area.

Try it out and let us know what you think. We hope you enjoy it!

-Metro Developer

Media types available from api.metro.net

The API delivers three different flavors of data: XML, JSON, and JSONP. This table lists the formats and their MIME types.

MIME type

Description

text/xml

XML is an encoded document format with arbitrary structure best consumed by machines.

application/json

JSON (an acronym for JavaScript Object Notation) is a lightweight text-based open standard designed for the exchange of human-readable data. This is the default.

application/javascript

Also known as JSON-P or JSON with padding. This is a JSON payload wrapped in a callback function. JSON-P is designed to be evaluated in the browser within a <script> element.

Metro’s Realtime API Collections

The interface is divided into four collections: Agency, Routes, Stops, and Vehicles. Each collection returns a list of elements. The element IDs tacitly suggest the URL for the element.

Method

Description

agencies

“lametro” is the only available Agency element (for now). Agency ID is case-sensitive, and should be all lower-cased.

routes

A list of routes available at the agency.

stops

A list of stops served by the route.

vehicles

A list of the current position of all vehicles belonging to the agency.

Consider these examples. The first retrieves a collection of routes operated by agency LA Metro. The second retrieves predictions for element stop 6033 . These links open in a new browser window. Go ahead and try them!

1. Is it necessary to use either the Metro Realtime API or Trip Planner API? Or is it fine if I host the Metro GTFS data on my own server and use it as the data source for my app?

2. I see that neither the Realtime API or Trip Planner API contain geo-location information for bus stops. Are there any plans for the Metro team to add such information within the competition time-frame? Currently GTFS data is the only way I can get geo-location info for all bus stops.

There’s more than one way to do it, but I would approach it this way. First get the current runs on the route then get the vehicle locations for those runs. Here’s an example using our default JSON data:

http://api.metro.net/agencies/lametro/routes/181/runs/

which gives me run_ids 181_55_1 and 181_43_0. Now get the list of all vehicle positions and find those run ids:

Thanks for the reply. I see how that method could be used to map the vehicle locations for all instances of a given run. But is there any way to isolate a single instance, for example, the next arriving bus? I’ve thought about using distance and heading, but this might be somewhat unreliable as most routes are not perfectly linear.

I actually think bus_id is the most appropriate attribute for what I’m trying to accomplish. The only problem is that it’s missing from the prediction results, so once you get a prediction there’s no way of showing the location of just that bus on a map.