Mike Williams provided some great feedback on my last post about Google Maps and coordinate systems. Let’s look into two of his comments in more depth.

First, he pointed out that my formula for calculating the number of tiles was a bit misleading:

`` Math.pow(2, zoom)``

This actually tells you either the number of tiles across or the number of tiles down. So at zoom level 2, there are 4 tiles across and 4 tiles down, for a total of 16. Thus, the correct formula is:

`` Math.pow(2, zoom) * Math.pow(2, zoom) or Math.pow(Math.pow(2, zoom), 2)``

Its worth stopping and thinking about this for a minute. Let’s do the math and see how many tiles Google has to generate to cover the Earth at different zoom levels.

At zoom level 20, it would require over 1 trillion tiles to cover the Earth.

Let’s do a quick back of the envelope calculation to figure out the storage requirements. If you download one of the image tiles, you’ll see that its an 8 bit png. I checked a few images of areas over land and saw that their sizes ranged from 8 to 16k.

So let’s say each land image occupies 10k, and that land occupies 25% of the Earth’s surface. Each ocean image is roughly 100 bytes, so let’s just ignore those (which is reasonable, since you only need to produce one nice blue png image as long as you don’t want to create any with labels like “Pacific Ocean”).

So as a rough estimate, the storage requirements in bytes can be calculated as:

``0.25 * numberOfTiles * 10000``

Working out the math we see:

At zoom level 14 you need 680 gigabytes of storage capacity, about the size of the largest hard drives available today. But remember the growth is exponential, so at zoom level 15 you need 2.7 terabytes space. By the time you reach zoom level 120 you’ll need 2,750 terabytes. Of course all the zoom levels are cumulative. If add up the total its around 3,700 terabytes – a number that just a few years ago would have been unimaginable but I’m sure is commonplace today for Google, Yahoo, Amazon, Yahoo, etc. Assuming you use 500 Gigabyte hard drives, that would be 7,400 hard-drives, not counting the same number needed to create a single backup.

The second point Mike brought up is that the farthest north, or south, that Google Maps covers is 85.05112877980660 degrees. How did they come up with that number? I have to admit I never considered it, but the answer is quite clever. It creates a perfect square – which of course is a lot easier to work with than a rectangle.

How do we know that – well let’s work through an example to see. At zoom level 0 we know that we want to cover the Earth with a single 256 by 256 pixel bitmap. Remembering from last time, to convert from y to latitude we use this formula:

`````` yToLat: function(y)
{
var latitude =  (Math.PI/2) -
(2 * Math.atan(