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

© 2010 some rights reserved by codesofa
Design by Stefan Sicher
Powered by WordPress