Deep understanding of the strongest desktop map control gmap.net---Principle

Source: Internet
Author: User

Some examples of domestic maps were introduced in the previous few

Deep understanding of the strongest desktop map control gmap.net---soso map

Deep understanding of the strongest desktop map controls gmap.net---Baidu map

We take Google Maps as an example, this chapter describes the principles of map loading.

projection (Projection)

Google Maps is based on the Mercator projection method, reproduced here (http://www.cnblogs.com/willwayer/archive/2010/06/11/1756446.html) The definition of the Mercator projection: Mercator (Mercator) projection , also known as "conformal cylindrical projection", the Dutch Atlas Mercator (Mercator) was drafted in 1569, assuming that the earth is surrounded by a hollow cylinder, its equator in contact with the cylinder, and then imaginary Earth Center has a lamp, the shape of the spherical surface projected onto the cylinder, and then the cylinder unfolded, This is the world map drawn by a standard parallel "Mercator projection" of zero (that is, the equator). From the ball to the plane, there is a conversion formula, here is no longer listed.

As you can see, Google has paved the entire map into a huge square, so just divide this huge square into a number of small plots on the layer.

Layers (Zoom) and pictures (Tile)

Based on the Mercator projection method, the entire Google Map is divided into 18 layers (Zoom): 0~17. Each time you manipulate (zoom) Google Maps, the images of the layers in the visible area are loaded in, so each layer is made up of a single picture,

The following Chrome browser development tools can be seen:

Each picture is called a Tile, which is often seen in the code, with the number of images per layer Tiles = 2 pow (2*zoom).

So the number of pictures for the first layer is: 2 pow (2*0) = 1

The number of images for layer 2nd is 2 pow (2*1) = 4

.....

The number of images for layer 17th is 2 pow (2 *) = 17179869184

latitude and longitude (lat,lng) and Grid (GRID)

So how does Google get pictures based on the current view? Google's approach (as well as other maps) is to divide the map into several meshes based on the Metoka projection method, each of which is a picture.

Then just convert the current latitude and longitude to a grid. The specific formula is not listed, too lazy to see, here is a section of code,

Tilecoordinate Locationcoord (double lat, double lon, int zoom), Lat,lon is the current latitude and longitude, zoom is the layer, and finally just know row and colum can be.

PublicClasstilecoordinate {Public Tilecoordinate (Double row,Double column,IntZoom) {This.row =RowThis.column =ColumnThis.zoom =Zoom;}PublicDoubleRowPublicDoubleColumnPublicIntZoom;}Static Tilecoordinate Locationcoord (Double lat,Double Lon,IntZoom) {if (System.Math.Abs (LAT) >85.0511287798066)ReturnNull;Double Sin_phi = System.Math.Sin (lat * System.Math.PI/180);Double norm_x = lon/180double norm_y = (0.5 * SYSTEM.MATH.LOG (1 + sin_phi)/(1-sin_phi)))/ System.Math.PI; double tilerow = System.Math.Pow (2, Zoom) * (1-norm_y)/2); double tilecolumn = System.Math.Pow (2, Zoom) * ((norm_x +  1)/2); return new           

OK, what's the use of getting this row and column, let's look at an example:

http://mt2.google.cn/vt/[email protected]&hl=zh-cn&gl=cn&src=app&x=22&y=12&z=5 &s=galile, return the picture as follows:

where x=22, y=12 is the row and Col mentioned earlier, and z=5 is the current zoom level (layer), the other parameters are the version and State, relatively fixed.

The above principle is finished, the domestic map may be slightly different, but the general idea is consistent.

Original link: http://www.cnblogs.com/enjoyeclipse/archive/2013/01/18/2865700.html

(turn) deep understanding of the strongest desktop map control gmap.net---Principle

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.