Google map coordinate system summary

Source: Internet
Author: User

From: http://logfei.blogspot.com/2008/11/blog-post_18.html
To locate a point in a map, the most common thing is to use a geographic coordinate to locate the point. However, Google map API also provides multiple sets of coordinate systems different from geographical coordinates, so that we can use different coordinates to locate the information displayed on the map as needed. I demonstrated these coordinates in the map on the right. You can move the mouse over the map to see them. Note that you need to expand the "mouse position" content :).
These coordinate systems can be summarized as follows (these systems are named by myself, and I do not know what to call them ):
1. geographic coordinate system
The geographic coordinate ranges vertically from the latitude line of the equator to the South and North Poles, respectively. The maximum value is 90. At the horizontal direction, the longitude line (meridian) of the old site of the Greenwich Mean observatory is used as the origin point, extending to East and West respectively, with the maximum value of 180. The elevation coordinates are ignored here.
There are two main ways to represent geographical coordinates: one is to represent the degree of second/degree, for example (39 ° 56 'n', 116 ° 20' E ); another way is to use a decimal number, such as (39.9333, 116.3333 ). When expressing a geographical coordinate, it is customary to use the sequence of first dimension and then longitude to describe a coordinate. In addition, for the previous coordinate, the direction is indicated by appending the abbreviations of letters, in the latter method, the X axis is generally used to represent the longitude, And the Y axis is used to represent the dimension. The corresponding symbols are added to the coordinates based on the principles of the Upper-North, lower-South, left-West, and right-East. Therefore, for (39.9333, 116.3333) We generally think of it as 39.9333 degrees north latitude and 116.3333 degrees east longitude.
In the Google map API, the last method is used to represent geographical coordinates, and glatlng is used to standardize the definition of a geographical coordinate. In the constructor of this class, the first parameter is a dimension, the second parameter is longitude. It should be noted that the order of these two parameters is different from the expression of x and y in the coordinate system, but represents a geographical coordinate according to the habit of geographical coordinate first dimension and longitude, this principle applies to all the places in the map API that need to express geographical coordinates.
2. Coordinate System of the image block
Google maps are spliced using a series of images of the same size, which are called blocks in Google Maps ). Therefore, you can think of Google maps as a series of grids filled with blocks/images. At different scaling levels, maps are divided into different numbers of grids. In details, when the scale level is 0, there is only one grid for the whole world map. Every time the scale level increases, all the grids are split horizontally and vertically. That is to say, corresponding to a specific scaling level N, the number of grids is the N power of 4, that is, 4n. The coordinate system composed of these grids is the block coordinate system.
In the block coordinate system, the world map with the zoom level of 0 is used as the origin point, and the world map is extended down (Y axis) and right (X axis) when the zoom level is increased, respectively, at the specified scaling level, we can use a coordinate to specify a specific graph block. If you want to replace a map block with your own image, this coordinate system can be used. There is no direct method in the Google map API to get the coordinate of the graph block. To get the coordinate, You need to continue reading it.
3. pixel Coordinate System
As mentioned above, Google Maps are spliced by a series of images of the same size. In fact, the size of these image blocks is fixed, all of which are 256x256 pixels. Therefore, at different scaling levels, the pixel size of a world map is also fixed. For example, when the zoom level is 0, the pixel size of a world map is 256 × 256 × 40. In this way, at a specific scaling level, because the pixel size of the world map is fixed, all the pixels that constitute the world map can form a complete coordinate system, we can also use pixel coordinates instead of geographic coordinates to specify a point on the map. This coordinate system is the pixel coordinate system.
The pixel coordinate system uses the upper left corner of the world map as the origin point when the zoom level is 0, and uses the same X and Y axes as the graph block coordinate system, when the scaling level increases, the system expands down and down to the right. The main difference between pixel coordinates and geographic coordinates is that the pixel coordinates are the two-dimensional coordinates of the plane, and the geographical coordinates are the two-dimensional coordinates of the surface (regardless of the elevation coordinates ).
You can use gprojection in the Google map API. fromlatlngtopixel (latlng, zoom) is used to obtain the corresponding pixel coordinates through geographical coordinates. For idea, you can use gprojection. frompixeltolatlng (pixel, zoom) is used to obtain the corresponding geographic coordinates from the pixel coordinates.
Now, let's look at how to obtain the corresponding graph block coordinates through pixel coordinates. As mentioned above, each graph block is a fixed size of 256x256 pixels. Therefore, you can use the pixel coordinate value divided by 256 and then get the coordinate of the graph block where the pixel coordinate is located. Use Code Speaker:
Math. Floor (x/256), X is the X value of the pixel coordinate. The result of this expression is the horizontal and vertical coordinates of the image block where the pixel is located. Algorithm Same.
4. Dom Relative Coordinate System
The Dom here refers to the container that loads the map on the page, which is generally a div element. It may be easier to think of this coordinate system as a dom-based element rather than a map-based coordinate system. The coordinates in this system specify the position of a point in the DOM container, use the upper left corner of the container as the origin point to extend down (Y axis) and right (X axis), respectively. The relative coordinates mean that the coordinate system is fixed relative to the map, and the origin does not change with the drag and drop of the map.
In the Google map API, gmap2.fromlatlngtocontainerpixel (latlng) can be used to obtain the position of a point in the DOM container on the map. Instead, you can use gmap2.fromcontainerpixeltolatlng (pixel) method to obtain the coordinates of a position in the DOM container on the current map. This coordinate system may be useful when you need to add custom controls on the DOM container and interact with the map.
5. Dom absolute Coordinate System
This coordinate system is relative to the previous system. It can be literally understood that it is a coordinate system located on a map rather than a relative map, if you scale the map without dragging it, you will find that the coordinate system and the Relative Coordinate System of the DOM overlap. However, once you drag a map, you will find their differences. You can try the difference in the map on the right. The conclusion is that the origin of the coordinate system is the point on the map that overlaps with the top left corner of the DOM container. When you drag a map, the origin will change with the map, the vertices on the left and above of the origin are represented by negative values.
The coordinates in the coordinate system and the geographic coordinates on the map can be converted using the gmap2.fromlatlngtodivpixel (latlng) and gmap2.fromdivpixeltolatlng (pixel) methods, these two methods can be used when you customize the overlay layer on a map.
One problem I haven't fully clarified is that when there are multiple world maps in the DOM container, that is, when the DOM container is large enough to accommodate the map blocks of multiple world maps, the relative coordinates of the Dom and the absolute coordinates of the DOM seem to be a bit disordered. If you have figured out the rules, please share them.
Finally, I mentioned gsize. When talking about the geographic coordinate system, I mentioned glatlng, which is a standard expression of geographical coordinates in Google map API. When it is used to represent non-geographical coordinates, gsize is needed. This is a standard expression of the coordinates in pixels. Unlike glatlng, the first parameter in its constructor represents the coordinates of the X axis, the second parameter represents the coordinate of the Y axis.

 

Http://kangzye.blog.163.com/blog/static/3681922320094810496421/

 

Http://kangzye.blog.163.com/blog/static/368192232009471055521/

 

 

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.