Google Map Data Algorithm

Source: Internet
Author: User
Use the Google map API to create a map for a project. Then I studied Google's image access. Algorithm It is not very difficult.
Let's take a look at our school chart.
Google Maps and Google Earth each level of each image has a URL, for example, the following figure of our school is the address of the http://kh.google.com/kh? V = 3 & t = trstrqqrsstttqtss (this is the image URL)

The variable v = 3 in the URL indicates that the projection algorithm of the satellite map uses the Mercator projection algorithm, and V = 2 indicates another algorithm (not supported)

Variable T = trstrqqrsstttqtssThis is the encoding of this image. The trstrqqrsstttqtss is calculated by an algorithm similar to the Q-tree. He uses the upper left, upper right, lower left, and lower right of an imageQ, R, t, sRespectively. Then recursion is performed in turn. The top layer isT.

If I want to see the top-level world map, the code is "T" and the URL is as follows:
Http://kh.google.com/kh? V = 3 & t = T click the link on the left and you will see the world map (maximum level ).

If I continue to find the graph of China (in fact, the upper right corner of the graph), the encoding is "TR" and the URL is as follows:
Http://kh.google.com/kh? V = 3 & t = tr click the link on the left to view the upper-right corner of the world map (that is, the area that contains China ).
And so on, you can find the map where you want to find it. (It is a simple explanation of this operation. The upper right corner uses a yellow box to indicate "r ")

The following is a tool in which you enter your latitude and longitude, And it will automatically recursion each image. You can step by step look at how Google Maps finds your location. Http://intepid.com/stuff/gmkh/

For more information about Q-tress, refer to this data structure book. The following figure is what I found in Wikipedia.

Below is the JavaScript code for this algorithmProgram(Including encoding and latitude and longitude)

Function Getquadtreeaddress ( Long, lat ) { VaR Pi = 3.1415926535897 ; VaR Digits = 18 ; // How many digits precision // Now convert to normalized square coordinates // Use standard equations to map into Mercator projection VaR X = ( 180.0 + Parsefloat ( Long )) / 360.0 ; VaR Y =- Parsefloat ( Lat ) * PI/ 180 ; // Convert to radians Y = 0.5 * Math. Log (( 1 + Math. Sin ( Y )) / ( 1 - Math. Sin ( Y ))); Y * = 1.0 / ( 2 * Pi ); // Scale factor from radians to normalized Y + = 0.5 ; // And make y range from 0-1 VaR Quad = "T" ; // Google addresses start with T VaR Lookup = "Qrts" ; // TL tr BL br While ( Digits- ) // (Post-Decrement) { // Make sure we only look at fractional part X-= Math. Floor ( X ); Y-= Math. Floor ( Y ); Quad = quad + Lookup. Substr (( X> = 0.5 ? 1 : 0 ) + ( Y> = 0.5 ? 2 : 0 ) , 1 ); // Now descend into that square X * = 2 ; Y * = 2 ; } Return Quad ; }

For more information, see:
Http://intepid.com/2005-07-17/21.50/

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.