mbus

3d buildings from Google Earth (Archimedes):  these and more are available in the set of online 3D Atlases of Ann Arbor.

Example

There are two versions - the Markers  & the 3D Bus . The data is pulled every 3 seconds.

How It Works

I am pulling the mbus live feed http://mbus.pts.umich.edu/shared/location_feed.xml. The file looks like this:

<livefeed>
  <item>
    <id>13</id>
    <latitude>42.281379699707</latitude>
    <longitude>-83.728157043457</longitude>
    <heading>96</heading>
    <route>Commuter Northbound</route>
  </item>
  <item>
    <id>23</id>
    <latitude>42.2872886657715</latitude>
    <longitude>-83.7194595336914</longitude>
    <heading>83</heading>
    <route>Bursley-Baits</route>
  </item>
...
</livefeed>

I wrote two Perl scripts, one for the Markers version (mbus.pl) and one for the 3D Bus version (mbus3d.pl). The scripts pull the live feed and convert it to a .KML file. There are a few important things about these scripts. The returned .KML has to be valid. The first line has to be the mime type. I just use a statement like this:

print "Content-type: text/html\r\n\r\n";

Afterwards the script has to print some opening KML statements and at the end some closing KML statement, as in the Markers version:

...
print "Content-type: text/html\r\n\r\n";
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
print "<kml xmlns=\"http://earth.google.com/kml/2.2\">\n";
print "<Document>\n";
print "\t<open>1</open>\n";
print "\t<Style id=\"bus\">\n";
print "\t\t<scale>0.5</scale>\n";
print "\t\t<IconStyle>\n";
print "\t\t\t<Icon>\n";
print "\t\t\t\t<href>http://maps.google.com/mapfiles/kml/shapes/bus.png</href>\n";
print "\t\t\t</Icon>\n";
print "\t\t\t<hotSpot x=\"0.5\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/>\n";
print "\t\t</IconStyle>\n";
print "\t\t<ListStyle>\n";
print "\t\t</ListStyle>\n";
print "\t</Style>\n";

... create <Placemark>s ...

print "</Document>";
print "</kml>\n";

In the center of the code all the <Placemark> are created, as in the Markers version:

...
print "<Placemark>\n";
print "\t<styleUrl>#bus</styleUrl>\n";
print "\t<name>$1</name>\n";
print "\t<description>$5 ($4deg)</description>\n";
print "\t<Point>\n";
print "\t\t<coordinates>$3,$2</coordinates>\n";
print "\t</Point>\n";
print "</Placemark>\n";
...

The file that is used in Google Earth just calls the script every 3 seconds - which is very simple, as in the Markers version:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<NetworkLink>
  <name>mbus</name>
  <Url>
    <href>http://www.larsi.org/cgi-bin/mbus.pl</href>
    <refreshMode>onInterval</refreshMode>
    <refreshInterval>3</refreshInterval>
  </Url>
</NetworkLink>
</kml>