introduction
This is my analyse about how google map works, et specially how the tiles are encoded. Google map uses pre-rendered tiles that can be obtained with a simple url. This article explains how to build the url for a tile from its geo coordinates (latitude/longitude)
Map Tile Encoding
Google map uses two differents algorithms to encode the location of the tiles.
For Google map, the url of a tile looks like : http://mt1.google.com/mt?n=404&v=w2.12&x=130&y=93&zoom=9 using x and Y for the tile coordinates, and a zoom factor. The zoom factor goes from 17 (fully zoomed out) to 0 (maximum definition). At a factor 17, the whole earth is in one tile where x=0 and y=0. At a factor 16, the earth is divided in 2x2 parts, where 0<=x<=1 and 0<=y<=1. and at each zoom step, each tile is divided into 4 parts. So at a zoom factor Z, the number of horizontal and vertical tiles is 2^(17-z)
Algorithm : to find a tile from a latitude, a longitude and a zoom factor :
latitude=90-latitude;
longitude=180+longitude;
double latTileSize=180/(pow(2,(17-zoom)));
double longTileSize=360/(pow(2,(17-zoom)));
int tilex=(int)(longitude/longTileSize);
int tiley=(int)(latitude/latTileSize);
In fact this algorithm is theorical as the covered zone doesn't match the whole globe.
Servers :
google uses 4 servers to balance the load. these are mt0, mt1, mt2 and mt3.
Tile size :
each tile is a 256x256 png picture.
For satellite Images, the encoding is a bit different.
the url looks like : http://kh0.google.com/kh?n=404&v=8&t=trtqtt the 't' parametres encodes the image location. The length of the parametre indicates a zoom level.
To see the whole globe, just use 't=t'. This gives a single tile representing the earth. For the next zoom level, this tile is divided into 4 quadrants, called, clockwise from top left : 'q' 'r' 's' and 't'. To see a quadrant, just append the letter of that quadrant to the image you are viewing. For example :'t=tq' will give the upper left quadrant of the 't' image. And so on at each zoom level...
algorithm : to find a tile from a latitude, a longitude and a zoom factor :
Collapse
double xmin=-180;
double xmax=180;
double ymin=-90;
double ymax=90;
double xmid=0;
double ymid=0;
string location="t";
double halflat = latitude / 2;
for (int i = 0; i < zoom; i++)
{
xmoy = (xmax + xmin) / 2;
ymoy = (ymax + ymin) / 2;
if (halflat > ymoy)
{
ymin = ymoy;
if (longitude < xmoy)
{
location+= "q";
xmax = xmoy;
}
else
{
location+=