A swiss public transit API (SBB and Google..)
Here we go.. After weeks of going back and forth between a crappy API (sbb.ch) with exact schedule and a nice API with wrong schedule (google.com), I finally merged them into one.
What are the capabilities of this API? Let’s make an example.
Given you entered from = “Feldstrasse 133, Zürich” and to = “Bern”.
- It then checks sbb.ch first - No hit.
- Then it checks google.com, which will return you a schedule with the next transit station from the address “feldstrasse+133, Zürich”
Ok, this is not a big deal.
In GottaGo, we often use (or almost everytime) the coordinates of a station. Let’s make another example.
Query: from=Triemli[8.495521,47.368052,0] and to=”Feldstrasse 133″.
The coordinates are then reverse geocoded, so that we get a city name.. Which is “Zürich” in this case.
- The API will first check sbb.ch for “Zürich, Triemli” to “Feldstrasse 133″, which will be no hit.
- It then checks sbb.ch for “Zürich, Triemli” to “Zürich, Feldstrasse 133″.
Note that the city is also added to the other parameter since we had no hit in the first place and the city name did not yet occur in the second parameter “Feldstrasse 133″. But no hit again..
- Then it checks google.com for “Zürich, Triemli” to “Feldstrasse 133″, which will be no hit, since there are a few more “Feldstrasse”s around in Switzerland.
- Ok, now the last resort: Check google with “Zürich, Triemli” to “Zürich, Feldstrasse 133″ - Ahhh, finally a hit :)
Why all this? Because of POI and address-book search.
SBB.ch doesn’t really provide a proper API for using POIs and addresses. And google doesn’t provide the comfort of saying “Fribourg” is the Mainstation of “Fribourg” and not the center of Fribourg, and the schedule is sometimes wrong, especially during holidays.
This results in a comfortable API which we can use to make also very simples queries like: from “Current Location” to “Liip” in `GottaGo’.
The URL to this API? http://couch.codesofa.com/api/transit.xml?from=station[longitude,latitude,0]; station2[longitude,latitude,0]&to=station3; station4[longitude,latitude,0]
(The coordinates are optional, and you can enter as many stations as you like, separated by “;”)
Eg: couch.codesofa.com/api/transit.xml?from=Triemli[8.495521,47.368052,0]&to=Bern
Btw.: Latest Beta of `GottaGo’ is out. (An iPhone app for swiss public transit). If you want a preview, see: http://liip.to/applyforbeta
Comments
sprain
August 6, 2008 at 2:38 pmhow official ist this api? not afraid sbb will just shut it off in a few days?
marc
August 6, 2008 at 10:27 pmof course I am.. But I actually believe in those guys as they should be lucky, that someone did the dirty work for them ;) but there is a fallback to google to the official API.. So that should be fine..
Russell Quinn
August 8, 2008 at 7:12 amHey! GottaGo is great, but I noticed an inconsistency in the interface with the SDK guidelines.
On the screen showing times, you use the arrow in a blue circle (sorry, I can’t remember the SDK name for it right now) to show you can navigate to the next page. However, this arrow should be used to indicate additional functionality for that table row.
I.e. It should mean that clicking the row itself does one thing, but clicking the actual arrow will take you to an alternative screen (maybe settings or something). You can see this in use in the wi-fi settings page.
In GottaGo, clicking on the row navigates to the next screen, but clicking the blue arrow actually does nothing at all (which is frustrating as clicking that side of the bar is typical behaviour for me).
The standard arrow (no blue background) should be used to indicate that clicking the row will navigate to another screen (and doesn’t have its own hit area), so I think this should be used on both the time listings page, but also the ‘closest’ page.
Russell
Marc
August 8, 2008 at 7:41 amHi Russel!
Thanks for your detailed remark! You are absolutely right about it. It’s called accessory view (the arrow on the right) and it really should also be clickable. It may, however, do the same action as the row itself. But the fact that it’s not clickable is a bug - of course. And it’s addressed in the next release :)
Russell Quinn
August 8, 2008 at 7:49 amGreat :)
Risotto
August 8, 2008 at 1:54 pmI was about to code exactly the same API as yours. I’m glad you did it first :) . I was also going to write an app almost like GottaGo. Writing that app also let me wonder why t.f. the sbb.ch site is so ugly to parse. I was pretty upset that there is no official SOAP or XML-RPC web-service to query from. Looks like SBB is just a very lame company
that doesn’t really care about it’s customers. After all, they are paid by the public! They really should be pressured to make that data available to everyone…
Well, anyway, if you’re looking for some help to further develop the app, I’m more than willing to join you. I did some work with the SDK too and as I said, I was halfway through with it too :) . In my prototype I did a nice google map integration which would be great in GottaGo too. So ping me, if you’re interested!