How Google map works

Source: Internet
Author: User
    • Plate: Technology
    • Author: Text/Pascal buirey/Amanda
    • Editor's Note: I analyzed the working principle of Google Map, especially how to perform tiles encoding. Google map uses pre-colored tiles, which can be implemented through a simple URL address.
    • Author Profile:
    • Source:

I analyzed how Google map works, especially how tiles is coded. Google map uses pre-colored tiles, which can be implemented through a simple URL address. This articleArticleIt explains how to create a tile URL from a geographical coordinate (longitude and latitude.

Map tile Encoding

Google map uses two typesAlgorithmEncode the location of the tile.

For Google Map, the tile URL is similar to: http://mt1.google.com/mt? N = 404 & V = w2.89 & X = 130 & Y = 93 & zoom = 9 use X and Y to set tile coordinates and amplification factors. The amplification factor ranges from 17 (completely reduced) to 0 (maximum ratio ). When the amplification factor is 17, the whole earth is displayed in a tile. At this time, x = 0, y = 0; when the amplification factor is 16, the Earth is divided into 2x2 parts, then 0 <= x <= 1 and 0 <= Y <= 1. Each time you zoom in, each tile is divided into four parts. Therefore, when the amplification factor is Z, the number of horizontal and vertical tile displayed is 2 ^ (17-z ).

Algorithm: Search for longitude and latitude and amplification Factors

// Correct the latitude to go from 0 (North) to 180 (south ),
// Instead of 90 (North) to-90 (South)
Latitude = 90-latitude;

// Correct the longpolling to go from 0 to 360
Longpolling = 180 + longpolling;

// Find tile size from zoom level
Double lattilesize = 180/(POW (2, (17-zoom )));
Double longtilesize = 360/(POW (2, (17-zoom )));

// Find the tile coordinates
Int tilex = (INT) (longpolling/longtilesize );
Int tiley = (INT) (latitude/lattilesize );

In fact, this algorithm is only theoretical, and the coverage area cannot match the whole earth.

Server:
Google uses four servers to maintain the load. They are mt0, MT1, MT2 and mt3.

Display location:
Each tile is in the .png format of 256x256.

For satellite images, the encoding method is a bit different.

Tile URL address is similar to http://kh0.google.com/kh? N = 404 & V = 8 & t = trtqtt, http://kh.google.com/kh? V = 34 & t = trtqtt. The parameter T is used to encode the image position. The parameter length indicates the zoom level.

T = t, the whole Earth can be observed, and only one tile represents the earth. The next zoom-in level is that the tile is divided into four quadrants, which start from the top left clockwise and start with 'q''rs'' and 'T' respectively '. After adding a letter to the quadrant of the image you observe, you can see the lower quadrant. For example, when 't= tq', the upper left quadrant of the 'T' image is given. And so on, which can represent each scaling level...

Algorithm: Search for longitude and latitude and amplification Factors


Collapse
// Initialise the variables;
Double X-min =-180;
Double xmax = 180;
Double ymin =-90;
Double Ymax = 90;
Double xmid = 0;
Double ymid = 0;

String location = "T ";

// Google use a latitude divided by 2;
Double halflat = latitude/2;
For (INT I = 0; I <zoom; I ++)
{
Xmoy = (xmax + xmin)/2;
Ymoy = (Ymax + ymin)/2;
If (halflat> ymoy) // upper part (Q or R)
{
Ymin = ymoy;
If (longpolling <xmoy)
{/* Q */
Location + = "Q ";
Xmax = xmoy;
}
Else
{/* R */
Location + = "R ";
Xmin = xmoy;
}
}
Else // lower part (T or S)
{
Ymax = ymoy;
If (longpolling <xmoy)
{/* T */
Location + = "T ";
Xmax = xmoy;
}
Else
{/* S */
Location + = "S ";
Xmin = xmoy;
}
}
}
// Here, the location shoshould contains the string corresponding to the tile...

Similarly, this algorithm is also theoretical, and the coverage area cannot match the whole earth.

Server:
Google uses four servers to maintain the load. They are kh0, kh1, kh2 and kh3.

Display location:
Each tile is a 256x256. jpg image.

Mocato projection

The above algorithm needs to be modified because mocato projection is used for display. In mocato projection, the distance between two weft threads is not necessarily equal, so the angle of tile is described based on its vertical position.

BelowCodeThe number of verticals of tile calculated from the latitude position of tile.

Collapse
/** <Summary> get the vertical tile number from a latitude using Mercator ptrojection formula </Summary> */
Private int getmercatorlatitude (double lati)
{
Double maxlat = math. Pi;

Double lat = lati;

If (LAT> 90) lat = lat-180;
If (LAT <-90) lat = lat + 180;

// Conversion DEGRE => radians
Double Phi = math. Pi * LAT/180;

Double res;
// Double temp = math. Tan (math. PI/4-phi/2 );
// Res = math. Log (temp );
Res = 0.5 * Math. Log (1 + math. Sin (PHI)/(1-math. Sin (PHI )));
Double maxtiley = math. Pow (2, zoom );
Int result = (INT) (1-Res/maxlat)/2) * (maxtiley ));

Return (result );
}

Coverage area:
In theory, the latitude range should be-90 degrees to 90 degrees, but in fact, because the mokto projection makes two levels of infinity, the coverage area is less than-90 to 90. The actual maximum latitude is obtained by formula Y = 1/2 (1 + sin (LAT)/(1-sin (LAT), where Pi = 3.1415926.

Protection:
Google map uses a protection mechanism to maintain high-quality services. If a user requires too many requests, Google map adds its IP address to the blacklist and sends an interesting message:

Google Error

We are sorry... your query is like a virus or a hacker application.Program. To protect our users, you cannot process your requests now. We will restore your access as soon as possible, so please try again. In addition, if you suspect that your computer or network is infected, you can clear the virus. Sorry for the inconvenience. I hope to see you again on Google.

To avoid being blacklisted, developers should use a hidden mechanism...

Interesting, right?

Here is a simple code written in C #: Download googlemapsample.zip-40.4 KB
Note: Google map changed the map parameter V. When I wrote this article, V is 2.12, but now it is 2.43. I think this is a bit like a version number or something.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.