This page comes from:
http://intepid.com/2005-07-17/21.50/
Sunday, July 17th, 2005
I’ve been playing around with the marvellous Google Earth and Google Maps, and just noticed how elegant the system for addressing image tiles is [specifically from Google Maps].
Google Maps now offers a satellite view as well as a map view, and does so using the former Keyhole database. The view is built using tiles— 256 pixel square JPEGs fetched from the the kh.google.com server.
As of this writing, the image URLs take the form:
http://kh.google.com/kh?v=projection&t=address
projection is either 2 or 3. Selecting 2 gives a plate carrée projection, while 3 provides a Mercator projection, ensuring that local features are uniformly scaled. [Update: projection type 2 is no longer supported]
address is a short string of letters encoding the location of a particular map square. The addressing mode is quite elegant, with the world recursively quartered until the desired detail level is reached. This simple heirarchical structure is known as a quadtree, and is commonly used in computer graphics. For whatever reason, Google labels the four quadrants q, r, s & t.
The topmost tile contains the entire world map, and is referenced with an address of t. Adding an s to this selects the lower-right quadrant of the map, and adding a further r selects the upper-right of that map, resulting in a tile containing most of Australasia. Each time an extra letter is added, we descend into a new quadrant, and this continues until the maximum detail is reached. So, for example, the hospital where I was born can be uniquely addressed [to within a hundred metres or so] using the URL:
http://kh.google.com/kh?v=3&t=tsrrtrsqsqqqrqrtsst
This page contains Javascript to returns all tiles containing a particular location, with each yellow quadrant marking the region occupied by the subsequent map. If you’d like to copy the code you can view the page source, or simply use the excerpts shown below. The first two functions are based on equations from Wikipedia’s entry on the Mercator Projection.