geOps Logo

Realtime

Realtime vehicle positions and prognosis data based on scheduled times, realtime updates and GPS locations. Available for S-Bahn Munich. Temporary access for the DBRegioDataHack in March 2021 only.

Websocket address with temporary API key for the hackathon:

wss://api.geops.io/realtime-ws/v1/?key=5cc87b12d7c5370001c1d655d8421f86bef24f9ebc726a60dc6ef1f9

We have an example using mobility-toolbox-js.

Our realtime vehicle position API delivers data in “channels” which support classic GET requests (REST API) or websockets with a custom protocol.

Each channel provides different data or a different view of the data. See the swagger documentation for details on the data returned.

Some interesting channels would be:

  • trajectory
  • newsticker
  • station
  • timetable_<ibnr>

Websocket API

This API is based on our redis-websocket-api and supports the same protocol:

Configuration:

BBOX <left> <bottom> <right> <top> // to only receive GeoJSON features within this box plus all messages which are not valid GeoJSON
PROJECTION epsg:<number> // causes all future GeoJSON features to be transformed to the given projection

Fetching data:

GET <key> // fetches all data from a channel
GET <key> <id> // fetches a specific item from the channel
SUB <key> // subscribes the websocket to a channel to get event-based updates
DEL <key> // unsubscribes the client from the channel
PING // causes a PONG response (to avoid timeouts or validate the connection)

A rudimentary example for subscribing to a channel from the #-location in the address bar:

<!DOCTYPE html>
<html>
  <head>
    <title>WebSocket demo</title>
  </head>
  <body>
    <script>
      var ws = new WebSocket(
          "wss://api.geops.io/realtime-ws/v1/?key=[YOUR_API_KEY]"
        ),
        messages = document.createElement("ol");
      ws.onmessage = function (event) {
        console.log("Ping!");
        var messages = document.getElementsByTagName("ol")[0],
          message = document.createElement("li"),
          code = document.createElement("code");
        content = document.createTextNode(event.data);
        code.appendChild(content);
        message.appendChild(code);
        messages.appendChild(message);
      };
      ws.onopen = function () {
        ws.send("SUB " + window.location.hash.slice(1));
      };
      window.onhashchange = function () {
        window.location.reload();
      };
      document.body.appendChild(messages);
    </script>
  </body>
</html>

Need help?

Feel free to reach out to the team via info@geops.ch