This is the Google Earth version of the famous University of Michigan "Magic Bus" page. There are two versions - the Markers  and the 3D Bus . The data is pulled every 3 seconds.

This is the old version. mbus has moved to doublemap and the feeds have changed. These are the new entry points:

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

<livefeed>
  <item>
    <id>5</id>
    <latitude>42.2826309204102</latitude>
    <longitude>-83.7335586547852</longitude>
    <heading>355</heading>
    <route>Northwood</route>
    <routeid>2<//routeid>
    <busroutecolor>990033<//busroutecolor>
  </item>
  <item>
    <id>16</id>
    <latitude>42.2847747802734</latitude>
    <longitude>-83.7317886352539</longitude>
    <heading>178</heading>
    <route>Intercampus to East Campus</route>
    <routeid>7<//routeid>
    <busroutecolor>990066<//busroutecolor>
  </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 (otherwise Google Earth freaks out - sometimes not so gracefully). 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, like 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, like 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 Goolge Earth just calls the script every 3 seconds - which is very simple, like 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>https://larsi.org/cgi/mbus.pl</href>
    <refreshMode>onInterval</refreshMode>
    <refreshInterval>3</refreshInterval>
  </Url>
</NetworkLink>
</kml>