Google Map Tile Graph algorithm analysis of __ algorithm

Source: Internet
Author: User
Tags pow sin

The article I saw last year http://www.earthplayer.com/bbs/viewthread.php?tid=321 is now inaccessible, and the address of the tile server is changed. Update and leave it for backup.

Algorithm analysis of Google map tile Map
MAP Tile Encoding

Google Map uses two algorithms to encode the location of the tile.

The URL address for Google Ditu,tile is similar to the following: http://mt2.google.cn/mt?v=cn1.6&hl=zh-CN&x=6678&y=3557&z=13&s= Galile uses x and y to set tile coordinates and magnification factors. The magnification factor is from 17 (completely reduced) to 0 (the maximum proportion). When the amplification factor is 17 o'clock, the whole earth is shown in a tile, at this time x=0, y=0, amplification factor is 16 o'clock, the earth is divided into the 2x2 part, then 0<=x<=1 and 0<=y<=1. Each tile is divided into 4 parts each time it is amplified. Therefore, when the magnification factor is Z, the number of horizontal and vertical tile displayed is 2^ (17-z).

The theoretical algorithm will look like the following:

Correct the latitude to go from 0 (north) to 180 (south),
instead (north) to-90 (south)
Latitude=90-latitude;

Correct the longitude to go from 0 to 360
Longitude=180+longitude;

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) (longitude/longtilesize);
int tiley= (int) (latitude/lattilesize);


Above is the assumption that the projection is planar.

In fact, Googlemap,51ditu uses the Mercator projection when it is displayed, so the above algorithm needs to be modified.
In the Mercator projection, the distance between two parallel lines is not necessarily equal, so the titley of the latitude corresponds to its vertical position.

The following code is the vertical number of tile computed from the latitude position of the tile

Collapse
/**<summary>get the vertical tile number from a latitude using Mercator ptrojection

/**<summary> This function obtains the corresponding latitude corresponding to the tile longitudinal axis serial number, the parameter is the latitude </summary>*/

private int getmercatorlatitude (double lati)
{
Double Maxlat = Math.PI;

Double lat = lati;

if (Lat >) lat = lat-180;
if (Lat < -90) lat = lat + 180;

Conversion Degre=>radians
Convert degrees to radians
Double phi = Math.PI * LAT/180;

            Double res;
             //Other posts on the Internet this place has a problem, should be a plus sign
           //double temp = Math.tan (Math.pi/4 + PHI/2);
           //res = Math.Log (temp);
           //The following sentence is the merge above
             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) * (Maxt Iley));

return (result);
}

Cover Zone:
Theoretically, the latitude range should be-90 degrees to 90 degrees, but in fact, because the Mercator projection makes the two class infinity, the covered strip is less than-90 to 90.

Finally, add Python validation code

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.