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+= "r";
xmin = xmoy;
}
}
else
{
ymax = ymoy;
if (longitude < xmoy)
{
location+= "t";
xmax = xmoy;
}
else
{
location+= "s";
xmin = xmoy;
}
}
}
again, this algorithm is quite theorical, as the covered zone doesn't match the full globe.
Servers :
Google uses 4 servers to balance the load. these are kh0, kh1, kh2 and kh3.
Tile size :
each tile is a 256x256 jpg picture.
Mercator projection
Due to the Mercator projection, the above algorithm have to be modified. In mercator projection, the spacing between to parallels is not constant. So the angle describe by a tile depends on it's vertical position.
Covered zone :
thoerically, latitude should go from -90 to 90, but in fact due to the Mercator projection which sends the poles to the infinites, the covered zone is a bit less than -90 to 90. In fact the maximum latitude is the one that give PI (3.1415926) on the Mercator projection, using the formula Y = 1/2((1+sin(lat))/(1-sin(lat))) (see the link in the Mercator paragraph)
Protection :
Google map uses a protection mechanism to keep a good quality of service. If one makes too much requests, google map will add its IP address to a blacklist, and send a nice message :
Google Error
We're sorry... ... but your query looks similar to automated requests from a computer virus or spyware application. To protect our users, we can't process your request right now. We'll restore your access as quickly as possible, so try again soon. In the meantime, if you suspect that your computer or network has been infected, you might want to run a virus checker or spyware remover to make sure that your systems are free of viruses and other spurious software. We apologize for the inconvenience, and hope we'll see you again on Google.
To avoid being backlisted, developpers should to use a caching mecanism if possible...
Sat Examples :
see the whole globe at http://kh0.google.com/kh?n=404&v=8&t=t
and the four corresponding quadrants : (note the 4 servers name to balance the load)
- http://kh0.google.com/kh?n=404&v=8&t=tq
- http://kh1.google.com/kh?n=404&v=8&t=tr
- http://kh2.google.com/kh?n=404&v=8&t=ts
- http://kh3.google.com/kh?n=404&v=8&t=tt
Map Examples :
see the whole globe at http://mt1.google.com/mt?n=404&v=w2.12&x=0&y=0&zoom=17
and the four corresponding quadrants :
- http://mt0.google.com/mt?n=404&v=w2.12&x=0&y=0&zoom=16
- http://mt1.google.com/mt?n=404&v=w2.12&x=1&y=0&zoom=16
- http://mt2.google.com/mt?n=404&v=w2.12&x=0&y=1&zoom=16
- http://mt3.google.com/mt?n=404&v=w2.12&x=1&y=1&zoom=16
nice isn't it ?
<script src="/script/togglePre.js" type="text/javascript"></script>
分享到:
相关推荐
How Google WorksHow Google WorksHow Google WorksHow Google WorksHow Google WorksHow Google WorksHow Google WorksHow Google WorksHow Google WorksHow Google Works
《How Google Works》是Google联合创始人兼首席执行官拉里·佩奇为书籍所写的前言。佩奇在前言中分享了他对未来职业生涯的早期设想,表达了他希望成为教授或创办公司的愿望,因为这两种职业都能让他拥有思考的自主权...
How google works. kindle edition
How Software Works
This is article of how search engine works
《How Google Works》是一本由谷歌的联合创始人兼首席执行官拉里·佩奇作序的书籍。书中详细阐述了谷歌的运营理念和工作方式,以及这家科技巨头是如何从一个简单的搜索引擎发展成为当今互联网世界的领导者的。从书中...
大脑是如何工作的 How the mind works 可以为你的某些工作找到科学依据
这篇教程“How C Programming Works”旨在帮助初学者理解C语言的工作原理和学习方法。 首先,我们来了解一下C语言的基础。C语言是由Dennis Ritchie在1972年为UNIX操作系统开发的,它是一种低级编程语言,但具有高级...
《How Tomcat Works》中文版一书详细剖析了Tomcat服务器的内部工作机制。该书基于Tomcat 4.1.12和5.0.18两个版本,深入讲解了其servlet容器的架构和运作原理,尤其是代号为Catalina的核心组件。 Tomcat是一个开源的...
《How Tomcat Works》是一份深入探讨Apache Tomcat工作原理的重要资源,包含了英文PDF文档、中文HTML翻译以及源代码,旨在帮助读者理解Tomcat服务器的内部运作机制。这份资料是IT从业者,特别是Java Web开发者、系统...
《How Tomcat Works》是一本深入探讨Apache Tomcat工作原理的书籍,中文版的提供使得国内开发者能够更方便地理解这一流行的开源Java Servlet容器。这本书不仅涵盖了Tomcat的基础知识,还详细解析了其内部机制,对于...
本文档标题为《经济机器是如何工作的--雷·达里奥》,由雷·达里奥撰写,其内容旨在阐述作者对经济体系的理解和工作原理。雷·达里奥是著名的投资者和桥水基金(Bridgewater Associates)的创始人,他的经济模型被...
谷 歌 C E O 斯 密 特 分 享 的 P P T H o w g o o g l e w o r k s 阐 述 了 谷 歌 的 企 业 经 营 哲 学 也 正 阐 述 了 这 个 时 代 互 联 网 时 代 的 商 业 哲 学 ">谷 歌 C E O 斯 密 特 分 享 的 P P T H o w...
How Linux Works 英文版PDF文字版 2nd Edition what Every superuser should know by Brian Ward San Francisco 介绍linux使用
《How Tomcat Works》这本书是理解Apache Tomcat服务器工作原理的宝贵资源,它全面深入地讲解了这个流行的Java Servlet和JavaServer Pages(JSP)容器的内部机制。书中的20个章节涵盖了从基础概念到高级特性的广泛...