When I request GTFS realtime data from my local Transit system, it gives me all data it has at once…
This is a ton of data that I don’t need. There’s so much data that my console runs out of space to scroll.
For example, if I want to keep track of where a bus currently is via it’s latitude and longitude, I need to constantly request it. This is going to be a huge amount of resources since it’s downloading everything all at once every time!
Is GTFS only meant to be retrieved in bulk or is there a way to retrieve specific data? Here is my current code to get realtime data:
const apiUrl = `https://gtfsapi.translink.ca/v3/gtfsposition?apikey=${apiKey}`;
axios.get(apiUrl, {
responseType: 'arraybuffer'
}).then(response => {
// Parse the GTFS Realtime data
const buffer = response.data;
const message = FeedMessage.decode(buffer);
const data = FeedMessage.toObject(message, {
longs: String,
enums: String,
bytes: String,
});
// Process the data as needed
log.debug("data:", data);
}).catch(error => {
log.error('Error fetching translink trip data:', error);
return res.status(500).json({ error });
});