Hack 21. Track the International Space Station

Track the International Space Station and the Space Shuttle in near-real time.

You can track anything on Google Mapsall you need is a source of data. Tom Mangan created his own site to track the Space Shuttle and International Space Station (ISS) at http://gmaps.tommangan.us/spacecraft_tracking.html.

The site tracks the location of the ISS and, when it is in orbit, the Space Shuttle, as shown in Figure 3-11. The excitement can come from being able to spot the Shuttle and ISS from the ground, and in watching on the map as they rendevous. When you first load the page you should get one or two markers, depending on whether the Shuttle is in orbit. If you leave the page open the markers leave a trail of where the ISS and Shuttle have been. Over the course of about 90 minutes (actually, 91.55 minutes for the ISS, according to the Wikipedia page at http://en.wikipedia.org/wiki/International_Space_Station), the characteristic sine wave shape of low Earth orbits appears. No, objects in space don't bounce around like tennis balls; this represents the effects of representing a three dimensional orbit onto a flat map. The first rule of cartography is that you always distort something!

Figure 3-11. Shuttle and ISS tracking, with an amusing note

Google's AdSense ads are often the funniest part of a page. Here we have a link to "NASA Space Shuttle for sale. Check out the deals now!" I don't think I want to buy an affordable spacecraft on eBay! Maybe in a few years.

3.6.1. How It Works

Most of the work happens in the JavaScript in the site's autoUpdate( ) function. autoUpdate( ) is called as soon as the page loads.


 

 

The autoUpdate function uses the GXmlHttp class from Google Maps to fetch the iss.js file from the server. You can take a look at the file at http://gmaps.tommangan.us/iss.js.

	-48.6;-11.7;369.8;-51.6;-31.9;291.1

 

This shows the latitude and longitude of the ISS first, and then that of the shuttle. The code reads the file, then splits the results into the array coords with the split method. The rest of the method is housekeeping to do a sanity check on the returned result, then adds the points to the current arrays of results for the Shuttle and ISS.

	function autoUpdate() {
	 var request = GXmlHttp.create();
	 request.open("GET", "iss.js", true);
	 request.onreadystatechange = function() {
	 if (request.readyState == 4) {
	 var response = request.responseText;
	 coords = response.split(';');
	 var valid = (coords[0]&&coords[1]&&coords[3]&&coords[4]
	 &&coords[0]>-90&&coords[0]<90&&coords[1]>-180
	 &&coords[1]<180&&coords[3]>-90&&coords[3]<90
	 &&coords[4]>-180&&coords[4]<180);

	 if (valid) {
	 map.clearOverlays();
	 var sPoint = new GPoint (coords[4],coords[3]);
	 var sMarker = new GMarker (sPoint,pinWhite);
	 if (coords[4] < -174) { sTrack=[]; }
	 sTrack.push (sPoint);
	 map.addOverlay(sMarker);

	 var issPoint = new GPoint (coords[1],coords[0]);
	 var issMarker = new GMarker (issPoint,pinRed);
	 if (coords[1] < -174) { issTrack=[]; }
	 issTrack.push (issPoint);
	 map.addOverlay(issMarker);

	 refreshCoords();
	 drawTrack();
	 }
	 }
	 }
	 request.send(null);
	 window.setTimeout ('autoUpdate()', 60000);
	}

 

The final trick is the last line of autoUpdate():

	window.setTimeout ('autoUpdate()', 60000);

 

This tells the window to timeout after 60,000 milliseconds, i.e., one minute. When it times out it calls autoUpdate() and starts the cycle again.

There is a script running on the server that queries the NASA site for the current position of the Shuttle and ISS, and then writes that out the iss.js file. You can use these same techniques to do dynamic updating of your own maps.

If you are the sort of person who goes in for space shuttle tracking, you'll like a couple of Tom's other projects at http://gmaps.tommangan.us/. He has a map that shows the current known locations of all of the SR 71 Blackbirds and aerial photos of Area 51. Both projects use his TPhoto extension to the Google Maps API, which lets you embed your own images within Google Maps [Hack #55].

3.6.2. See Also

  • NASA's Satellite Tracking Page, which includes applications to track many different satellites, although not with Google Maps: http://science.nasa.gov/realtime/.






Google Maps Hacks
Google Maps Hacks: Tips & Tools for Geographic Searching and Remixing
ISBN: 0596101619
EAN: 2147483647
Year: N/A
Pages: 131
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net