Getting routeConfig for multiple routes and/or getting data for nearby stops

62 views
Skip to first unread message

Ahmed El-Khuffash

unread,
Jun 4, 2020, 3:21:01 PM6/4/20
to NextBus API Discussion
I'm not sure if this group is still active...

I'm planning to add a simple piece of functionality to get bus/street car times for stops near a user, so I need to search by latitude/longitude.

Unfortunately, looking at the public list of APIs, there's no way to do this directly (surprising!). I do see the NextBus official app uses a separate API, that does seem to have this. Is this API publicly accessible?

I'm guessing it isn't.

The only alternative I could figure out:
  • Make an API call to routeList to get all 174 routes in the agency I want (TTC)
  • Make an API call to routeConfig 174 times to get the config details for each route, including start and stops
    • routeConfig's documentation says if you omit the r parameter, you'll get all the agency's routes if it's less than a 100, but you'd have to batch calls if they're more than a 100
    • Is there any way to batch this call with multiple route tags? I couldn't figure it out
  • Do a search in-app for all stops found in routeConfig
  • Do a call to predictionsForMultiStops to get the predictions for the stops found in the step above
Is there an easier method or some sort of other logic I'm not seeing?

Steve Caine

unread,
Jun 5, 2020, 12:50:19 PM6/5/20
to NextBus API Discussion
I have not used this API in many years because NextBus dropped the agency my app follows (Boston MBTA), but I think I recall that you could request multiples in routeConfig by chaining routeTags, ex. "r=1,2,3,4,5". Give it a try.

If documentation says some calls must be batched, that means such a batch command is available. No (competent) service would document a requirement that could not be fulfilled by their API.

Ahmed El-Khuffash

unread,
Jun 5, 2020, 12:54:01 PM6/5/20
to nextbus-a...@googlegroups.com
I've tried that, but unfortunately I get an error. I also tried chaining it with a pipe as a separator.

I also tried passing multiple r=94&r=74, but that only returns the first one

--
You received this message because you are subscribed to the Google Groups "NextBus API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextbus-api-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nextbus-api-discuss/2aee3529-b79a-46c4-a901-aa817a600d3fo%40googlegroups.com.

Steve Caine

unread,
Jun 5, 2020, 12:58:11 PM6/5/20
to NextBus API Discussion
In fact, it may be possible to request ranges, e.g., "r=1-99".

Darwin O'Connor

unread,
Jun 5, 2020, 12:59:11 PM6/5/20
to NextBus API Discussion
The way to do this is to load the routeConfig data into a database and they query it for what you are looking for.


On Thursday, June 4, 2020 at 3:21:01 PM UTC-4, Ahmed El-Khuffash wrote:

Steve Caine

unread,
Jun 5, 2020, 1:02:00 PM6/5/20
to NextBus API Discussion
Sorry, I didn't see your reply until posting my followup. Beyond that suggestion, I don't have anything to offer w/o diving back into the API, which I currently don't time to do.

Steve Caine

unread,
Jun 5, 2020, 1:27:24 PM6/5/20
to NextBus API Discussion
Yes, but his issue is how to acquire that data in the first place so it can be put into a database. Once you've done that, the challenge becomes knowing when a routeConfig has changed.

My app (used to) make a separate request for each route served by a given stop when users asked for predictions for that stop. It didn't batch, but it did cache (keeping the XML response for up to 7 days). 

If I were to have added a "find nearest stops" feature, I would have used the approach you suggest. Since Boston MBTA is no longer served by NextBus, the issue is moot for me.

But the approach I would have used would be to make the 176 requests from my own computer -- spaced over time -- then accumulate those XML files and create a database which I would preload in the app. The app would then update its copy of that database over time with new routeConfig requests as needed, following some logic I would have devised for that need.
Reply all
Reply to author
Forward
0 new messages