David Janes' Code Weblog

November 8, 2008

Switching between mapping APIs and universal zoom levels

html / javascript,maps · David Janes · 3:03 pm ·

Did you know that Google Maps, Yahoo Maps and Virtual Earth all use the same map tile resolutions? That is, you can actually seamlessly switch between mapping systems and have everything line up exactly the same way. If you’d like to play with this, look at our map examples:

But it’s even easier to show this using a graphic (thank you to Alistair Morton of Peapod Studios for compositing): All Maps

Table of map zoom level equivalents

Google Maps and Virtual Earth the same zoom levels, excepting that Google has a level 0. Bigger numbers are closer to the ground, smaller numbers are up into space. Yahoo Maps has fewer levels to work with – it doesn’t let you drill down below the block level. Yahoo numbers its zoom levels the opposite of Google and Virtual Earth, small numbers being closer to the ground and so on and so forth.

To allow seamless switching of data between APIs, I propose here universal zoom levels, which can be used as-is on any of these mapping APIs. To avoid confusion of which type of zoom level one is using, we use the negative number range for universal zoom levels. As Google and Microsoft are using the same zoom levels, I’ve decided that the universal zoom levels should simply be the inverse of their zoom levels, bounded by (-1, -19) inclusive.

Google Maps Virtual Earth Yahoo Maps Universal
Ground 19 19 - -19
18 18 - -18
Block 17 17 1 -17
16 16 2 -16
15 15 3 -15
14 14 4 -14
City 13 13 5 -13
12 12 6 -12
11 11 7 -11
10 10 8 -10
9 9 9 -9
8 8 10 -8
State 7 7 11 -7
6 6 12 -6
5 5 13 -5
4 4 14 -4
3 3 15 -3
2 2 16 -2
Space 1 1 17 -1
0 - - -

Conversion Formulae

Here’s Javascript to convert between your favorite mapping API’s zoom levels and universal zoom levels. Note that all to_native functions accept positive numbers as-is.

zoom = {
  google : {
    to_univeral : function(native) {
      return  Math.min(-1, -native);
    },

    to_native : function(universal) {
      return  universal > 0 ? universal : -universal;
    }
  },

  virtual_earth : {
    to_univeral : function(native) {
      return  Math.min(-1, -native);
    },

    to_native : function(universal) {
      return  universal > 0 ? universal : -universal;
    }
  },

  yahoo : {
    to_univeral : function(native) {
      return  Math.min(-1, native - 18);
    },

    to_native : function(universal) {
      return  universal > 0 ? universal : Math.max(universal + 18, 1);
    }
  }
};

End Notes

A truly universal zoom level would just use altitude; dealing with a simple integer is easier and less complication prone though. MapQuest is not included in this post as its tiles do not line up with the other APIs.

11 comments

  1. […] Zoom levels are returned in native format and “universal format“ […]

  2. […] article Switching Between Mapping APIs and Universal Zoom Levels at David Janes’ Code Weblog explains that the mapping systems differ in their zoom […]

  3. Cool post – I’ve often wondered whether this was just coincidence or some sort of ‘standardisation’ (or a function of sources/providers of the imagery and maps).

    The same is true of OpenStreetMap tiles, and the ‘overlays’ used by Google (for streets & streetview) and Yahoo. Google Moon & Mars also use the same tile system, but with fewer zoom levels (6 or 7). In other countries (ie. outside the USA) the ‘lowest’ zoom level varies as they don’t always have high-resolution imagery for each country (and across the oceans).

    You can play interactively at http://silverlightearth.com/2/ (although due occasional updates by the tile servers some selections occasionally won’t load). For example, you can overlay Googles ‘blue glow’ streetview indicator over OpenStreetMap or overlay Googles roads over Virtual Earth’s or NASAs satellite imagery…
    http://conceptdev.blogspot.com/2008/08/silverlightearth-gets-openstreetview.html

  4. […] David Janes: “Did you know that Google Maps, Yahoo Maps and Virtual Earth all use the same map tile resolutions? That is, you can actually seamlessly switch between mapping systems and have everything line up exactly the same way.” Examples provided. Google has one wider zoom than the others; Yahoo lacks the two closest levels of Google and Virtual Earth. Via Global Nerdy. […]

  5. It’s extremely likely that Microsoft and Yahoo! followed Google’s lead here. But the derivation is actually quite logical. The first ingredient is the Mercator projection, which is the best projection suited for slippy maps like these since it preserves shape and angles. (Google once used a plate caree projection for the satellite maps but quickly abandoned it because circles became ellipses far from the equator.) The second ingredient is using a quad-tile implementation with 256-pixel-width map tiles; it’s also quite convenient that a square cut of the Mercator projection of the world spans from ~85°S to ~85°N, which covers most of the places most people would be interested at (too bad for the poles).

    What’s not logical is the fact that Google uses a spherical approximation of the WGS84 datum (which is actually not too inaccurate) for computational efficiency. The question is whether Microsoft and Yahoo! also uses this spherical approximation. If not, there will be places on the three maps that will be off. It’s been confirmed over at http://cfis.savagexi.com/2006/05/03/google-maps-deconstructed that Microsoft also uses a spherical approximation. Yahoo is likely doing the same thing.

  6. What a marvellous article — will crosspost & comment with full kudos!

  7. (I just wrote a lengthier version of this comment, then my browser ate it. rewriting, sad.)

    Eugene’s right on the mark with his explanation. We did a bunch of this same exploration about two years ago with Modest Maps, summarized here:
    http://modestmaps.mapstraction.com/trac/wiki/TileCoordinateComparisons

    An additional convenience of the scheme used by Google & VEarth gets you is the ability to use simple arithmetic in your exponents with your map code. With the furthest-out zoom level equal to zero, you can easily determine how many tiles your complete map contains at each zoom, and rapidly convert between them. For example, at zoom level zero, 2^0 = 1 tiles across to cover the whole world; at zoom level one, 2^1 = 2 tiles across to cover the whole world; at zoom level two, 2^2 = 4 tiles across to cover the whole world, etc.

    Yahoo’s choice of numbering scheme makes probably the least sense of all, because they’ve given themselves an implied maximum zoom.

    The Modest Maps python branch has some of the most succinct bits of code & math for dealing with this:
    http://modestmaps.mapstraction.com/trac/browser/trunk/py/ModestMaps/Tiles.py
    http://modestmaps.mapstraction.com/trac/browser/trunk/py/ModestMaps/Google.py
    http://modestmaps.mapstraction.com/trac/browser/trunk/py/ModestMaps/Microsoft.py
    http://modestmaps.mapstraction.com/trac/browser/trunk/py/ModestMaps/Core.py#L43

  8. David Janes · 2008-12-07 07:11

    Thanks Michal. And then Askimet ate it, sorry for taking so long to get it up here!

  9. […] Migurski added a very informative comment about tiling levels here, with a pointer to way more detailed information […]

  10. Shivaji · 2008-12-16 05:39

    Hi, I need to take a road and buildings all the shapes is that possible for me.
    And i need all this things are need in SHP files
    thanks.

  11. Hi,

    I just would like to mention here the mashup for tile coordinates detection:

    http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/

    You can search a place, or zoom&pan to it and you will see directly the coordinates of the tiles and bounds in several systems.

    On the website is also the Python module (open-source) for calculating and conversion of all the systems…

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress