Integrating Real-time Traffic Information


The content in this article may still be applicable to the current version of the Bing Maps AJAX Control 6.3, but it uses a previous version of the Bing Maps AJAX Control 6.3 which is no longer supported. More information about the current version of the Bing Maps AJAX Control 6.3 is found in the Bing Map Control SDK.

In the United States, Bing Maps already provides real-time traffic visualization. The data comes from and is available in several Metropolitan Areas, as shown on the following map:

Figure 1 Metropolitan areas with real-time traffic information available

The implementation in Bing Maps is very nice and shows the consequences of traffic incidents and construction sites as color-coded overlays for both sides of the street.

Figure 2 Traffic information overlays in Bing Maps

Unfortunately, these overlays are not available for maps outside of the United States, and even if they were, we couldn’t use them in a Bing Maps custom application. An alternative is required in order to provide traffic data for European countries.

A very common source for real-time traffic information is the Traffic Message Channel (TMC), where the coded traffic messages are broadcasted by radio stations over an RDS-channel. TMC messages can be received by a TMC receiver which is often a component of Personal Navigation Devices (PND) or in-car navigation systems. Besides the fact that you would need a TMC receiver, the other drawback to working with TMC messages is that TMC uses a code to compress the messages and you would need to decode the message first before using it. In addition, you would need a location table to determine the position of the incident.

A better alternative in this scenario has been developed for the European Commission. There are a couple of telemetric services under the roof of CENTRICO ( CENTRICO is a Euro-regional Project implementing Intelligent Transport Systems (ITS) to improve the efficiency of the Trans European Road Network (TERN) in order to keep people and goods moving. The CENTRICO project is supported by the DG TREN of the European Commission.

One of CENTRICO’s projects is TIS (Traveler Information Services). It is the policy of most of the CENTRICO authorities that dissemination of traffic information should be eventually left to commercial service-providers. Therefore they make their information available to such service providers.

Within TIS there is the OTAP (Open Travel data Access Protocol) project ( OTAP is an easy access point on the internet where Service Providers can retrieve traffic information from the different TICs (Traffic Information Centers) and other information suppliers within the CENTRICO area. The TICs make their traffic information available through the Internet by using standard technology and common formats based on XML and XSD.

Each center continues to provide and own data for its geographic area and is responsible for the quality of data and service. Contracting procedures and contracts can vary between TICs. The OTAP interface was made as 'easy' as possible by preferring widespread technologies with low technological entry thresholds and giving the highest priority to choices that offer harmonization, minimal costs, and maximal stability for both the centers and the service providers.

Figure 3 TIC/OTAP model

Quality of data will vary from country to country and so will the cost.

OTAP data is available as an XML stream. All of the streams are geo-coded for the start and end points and a point in the middle of the traffic disturbance. There are different streams for current and future planned events as well as unplanned events.

Figure 4 Directory of OTAP data streams for England

Bing Maps can consume GeoRSS feeds and overlay the information. So the general strategy we will use is to use the Extensible Style Language Transformation (XSLT) to transform the XML stream in an GeoRSS feed and consume the feed in Bing Maps.

To gain access to the OTAP XML streams you will need to e-mail the contact persons for the country in which you are interested. You will find the contact information here:

  • There is a Java SDK for development with OTAP data but since it is pure XML you can use various coding languages. I used a VB.NET application written with Microsoft Visual Studio 2005 to receive the XML stream and perform the transformation.

  • You just need a text editor to create the file for the XSL Transformation but I used Stylus Studio 2006 XML because it is a very nice and easy-to-use tool.

  • You also, of course, need Bing Maps. There is an excellent interactive SDK and a reference SDK available here: Optionally you can download the reference SDK here:

Let’s have a look at the data source first. We need to investigate the OTAP XML schema and the required format for the GeoRSS feed. Then we define the mapping rules for an XSLT and finally we write a small program to periodically pull and trans-form the data.

You will find the OTAP specifications here:

For the purposes of this article, we will concentrate only on unplanned events, but we could also retrieve current and future planned events in a similar fashion. In the screenshots below, you can see the XML tree for one incident including the data for the UK. Please note: In the UK there is currently information only for the motorways.

I am using the latitude and longitude of the framed point (the middle of the traffic incident), the description, and the estimated delay caused by this incidents.

Figure 5 Partial view of XML file representing traffic incident data, showing location and description of incident

As you can see, there is a lot more information that you could use, if necessary. For example, you could make use of the lat/long of start/end points of the incident.

Figure 6 View of XML file representing traffic incident data, showing delay time caused by incident

There are various specifications for GeoRSS feeds. The Bing Maps AJAX Control 6.3 supports the W3C Basic Geo Vocabulary (see In this example, we use the WorldKit ( implementation for which we simply need a <geo:lat> and a <geo:long> tag to describe the location.

<?xml version='1.0' ?>
<rdf:RDF xmlns:rdf="" 
    <title>M6 southbound between J10 and J9</title>

Listing 1 GeoRSS feed XML

Using Stylus Studio 2006 XML we define the mapping rules for the XSL Transformation.

Figure 7 Creating an XSLT stylesheet in Stylus Studio 2006

The XSL-file will look like this:

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
  <xsl:template match="/">
    <rdf:RDF xmlns:rdf="" 
    <xsl:for-each select="situationPublication/situation/situationElement">
          <xsl:value-of select="elementlocation/framedPoint/name/descriptor"/>
          <xsl:value-of select="consequence/delay/delayTimeValue"/>
          <xsl:value-of select="elementlocation/framedPoint/wgs84/latitude"/>
          <xsl:value-of select="elementlocation/framedPoint/wgs84/longitude"/>

Listing 2 The Stylesheet to transform the data to GeoRSS

Now that we know the source OTAP-format and destination GeoRSS-format and we have defined the rules for the XSL transformation, we need to make sure that we pull the data periodically from the OTAP server and apply the transformation to it.

In Visual Studio 2005, we create a new project for a Windows Application. On the Windows Form, we add a button and two disabled text boxes.

Figure 8 Creating a Windows forms application to transform the feed

We then write code to create a WebRequest to the OTAP server and capture the response in a data stream. We use an XmlTextWriter to write the data stream to the local hard drive into the file OTAPtemp.xml.

Finally, we use the XSL file we created earlier to transform the OTAPtemp.xml file into the GeoRSS format we need and write it back to the file GeoRSS.xml. The complete process is framed by a While…Do loop so that we refresh the data every minute. You’ll find the complete code below.

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.Text
Imports System.Net
Imports System.Threading

Public Class Form1
  Private inputfilename As String = "OTAPtemp.xml"
  Private outputfilename As String = "GeoRSS.xml"
  Private stylesheet As String = "OTAP2GeoRSS.xsl"

  Private Sub Button1_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Button1.Click
    Dim i As Integer = 0

    Do Until txtStatus.Text = "Stopped"
      txtStatus.Text = "Reading"
      Dim request As WebRequest = WebRequest.Create( _
      Dim myCredentials As New NetworkCredential
      myCredentials.UserName = "YOUR_USERNAME"
      myCredentials.Password = "YOUR_PASSWORD"
      request.Credentials = myCredentials
      Dim response As WebResponse = request.GetResponse()
      Dim dataStream As Stream = response.GetResponseStream()

      Dim reader As New StreamReader(dataStream)
      Dim responseFromServer As String = reader.ReadToEnd()
      Dim OTAPWriter As New XmlTextWriter(inputfilename, Encoding.UTF8)

      Dim xslt As New XslTransform
      Dim xpathdocument As New XPathDocument(inputfilename)
      Dim GeoRSSwriter As New XmlTextWriter(outputfilename, Encoding.UTF8)
      GeoRSSwriter.Formatting = Formatting.Indented
      xslt.Transform(xpathdocument, Nothing, GeoRSSwriter, Nothing)
      txtStatus.Text = "Waiting"
      i = i + 1
      txtCycles.Text = i.ToString + " Cycles"
  End Sub
End Class

Listing 3 VB.NET code for regularly refreshing local traffic data

Ideally, we would want to turn this process into a Windows Service and schedule it to run at intervals of our choosing. However, building a Windows Service is beyond the scope of this article.

Consuming a GeoRSS feed in Bing Maps is extremely simple. You only need to make sure that the GeoRSS feed and any images you might want to use can be described by a URL. We can create a Virtual Directory in Internet Information Service Manager (IIS) MMC and point it to the directory in which our application periodically writes the GeoRSS.xml file.

We can then create a simple HTML file with the following code in order to display the data visually.

<script src=""></script>

  var map = null;
  var layerid = 1;

  function GetMap()
    map = new VEMap('myMap');
    map.LoadMap(new VELatLong(53.956, -17.5781), 7 ,'h' , false);
    AddDataLayer( 'GeoRSS.xml', 'images/trafficicon.GIF' );


   function AddDataLayer( dataSource, dataIcon )
    var veLayerSpec = new VELayerSpecification();
    veLayerSpec.Type = VELayerType.GeoRSS;
    veLayerSpec.ID = layerid;
    veLayerSpec.LayerSource = dataSource;
    veLayerSpec.Method = 'get';
    veLayerSpec.IconUrl = dataIcon;
    veLayerSpec.FnCallback = onFeedLoad;


<body onload="GetMap();">
  <div id='myMap' style="position:relative; width:400px; height:400px;"></div>


Listing 4 ABing MapsBased Traffic Report

As long as our HTML page is in the same file as our GeoRSS.xml output file, then our users should see a map showing the United Kingdom, complete with all known traffic incidents.

As mentioned earlier you’ll find the complete interactive SDK as well as a reference SDK for the Bing Maps AJAX Control 6.3 here:

This article is an updated revision of an original article contributed by Johannes Kebeck. The update was performed by Robert McGovern MVP (Bing Maps/MapPoint).