
TransitLand
TransportationTransit Aggregation. Transitland brings together many sources of transit data to build a directory of operators and feeds that can be edited by transit enthusiasts and developers. Transitland contains several interlocking parts, including the Feed Registry, the Datastore, and the Playground. Transitland Feed Registry is a directory of transit operators and data feeds. Through the Feed Registry, you can browse operators, feeds, and usage and license information, as well as contribute additional feeds. The directory is a view into Transitland’s Datastore API. Transitland Datastore brings together data from the Feed Registry with contributions, edits, and fixes from transit enthusiasts and developers. The Datastore is a hosted service that provides a web API for querying and editing. Mobility Explorer is an interactive interface for querying the Transitland Datastore API. Transitland Dispatcher is an administrative interface, which also queries the Datastore API. Valhalla is an open-source routing engine that consumes data from the Datastore API and offers journey planning and analysis.
📚 Documentation & Examples
Everything you need to integrate with TransitLand
🚀 Quick Start Examples
// TransitLand API Example
const response = await fetch('https://transit.land/documentation/datastore/api-endpoints.html', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
Exploring Transit Land's Public APIs
Transit Land is a platform that curates and aggregates transit data from transit agencies and other sources. They offer public APIs that provide access to a wealth of transit data that you can use to build apps or improve existing ones.
In this article, we'll explore some of Transit Land's APIs and how to use them in JavaScript.
API Endpoints
Transit Land offers several APIs for accessing transit data. Here are a few of them:
https://api.transit.land/api/v2/schedule_stop_pairs
- Returns a list of all transit trips that stop at a given stop.https://api.transit.land/api/v1/feed_versions
- Returns a list of feed versions available in Transit Land's Datastore.https://api.transit.land/api/v2/router/router
- Calculates possible routes between two stops using GTFS transit data.
Let's take a look at how to use these APIs in JavaScript.
Making API Calls in JavaScript
To make API calls from a JavaScript application, we can use the fetch()
function, which is native to modern web browsers.
Example: Schedule Stop Pairs
To retrieve a list of all transit trips that stop at a given stop, we can make a GET
request to the schedule_stop_pairs
endpoint, passing the stop ID as a parameter.
fetch('https://api.transit.land/api/v2/schedule_stop_pairs?origin_onestop_id=o-9q8y-nfantacitypark&date=2019-05-03')
.then(response => response.json())
.then(data => console.log(data));
In this example, we're requesting schedule stop pairs for the stop with the ID o-9q8y-nfantacitypark
on May 3, 2019.
Example: Feed Versions
To retrieve a list of feed versions available in Transit Land's Datastore, we can make a GET
request to the feed_versions
endpoint.
fetch('https://api.transit.land/api/v1/feed_versions')
.then(response => response.json())
.then(data => console.log(data));
Example: Router
To calculate possible routes between two stops using GTFS transit data, we can make a POST
request to the router
endpoint, passing the origin and destination stop IDs in the request body.
const requestBody = JSON.stringify({
origin_onestop_id: 'o-9q8y-nfantacitypark',
destination_onestop_id: 'o-9q8y-nfanthewestend'
});
const headers = {
'Content-Type': 'application/json'
};
fetch('https://api.transit.land/api/v2/router/router', {
method: 'POST',
headers,
body: requestBody
})
.then(response => response.json())
.then(data => console.log(data));
In this example, we're calculating possible routes between the stops with the IDs o-9q8y-nfantacitypark
and o-9q8y-nfanthewestend
.
Conclusion
In this article, we've explored a few of Transit Land's public APIs and how to use them in JavaScript. With these APIs, you can access a variety of transit data that you can use to build powerful transit-related apps and solutions.
📊 30-Day Uptime History
Daily uptime tracking showing online vs offline minutes