I have heard that the Google map API has been made public, but there is no time to read it. Today I have read two articles about this.ArticleI think it's good. I understood something.
Article 1:[Source code] HOWProgramUsing Google map resources
Original address: http://bbs.msproject.cn/default.aspx? G = posts & t = 205
[Translation]
Pascal buirey by how Google map works
[Development Environment]
In this example, the development language C # can be appliedAny language
[Introduction]
This article analyzesGoogle MapsHow it works, and specifyTileHow is it encoded. Google map uses the tile that can be obtained by sending a simple URL. This article explains how to obtain the corresponding tile URL through the geographic longitude and latitude.
[Tile encoding]
Google map provides two differentAlgorithmThe location of the encoding tile.
In Google Maps, a tile URL is generally like this:Http://mt1.google.com/mt? N = 404 & V = w2.12 & X = 130 & Y = 93 & zoom = 9, X and Y are the coordinates of tile (latitude and longitude), and a display scale. Zoom factor: from 17 (full zoomed out) to 0 (maximum precision ). When the ratio is 17, the whole earth is displayed in a tile, x = 0 and Y = 0; when it is 16, the Earth is divided into 2 × 2 parts, 0 <= x <= 1, 0 <= Y <= 1. Therefore, if the zoom factor is Z, the total number of horizontal and vertical tile is 2 ^ (17-z ).
[Use the latitude, longitude, and display ratio to find a tile algorithm]
Code:
// 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 theoretical because the covered regions do not match the world.
[Server]
Google uses four servers to balance the load. They are mt0, MT1, MT2, and mt3.
[Tile size]
Each tile is a 256x256 PNG image.
[Satellite images]
The satellite image encoding is different, and its URL is generally as follows:Http://kh0.google.com/kh? N = 404 & V = 8 & t = trtqttThe t parameter encodes the image position, and the T Length indicates the zoom level.
To see the world, set t to t. For the next display level, tile is divided into four quadrants, which are Q, R, S, and t clockwise, you can attach this character to the end of T. For example, t = TQ indicates the upper left quadrant. And so on ......
The algorithm is as follows:
Code:
// 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 theoretical.
[Server]
Google uses four servers to balance the load. They are kh0, kh1, kh2, and kh3.
[Tile size]
Each tile is 256x256JPGImage
[Mercator projection]
The above algorithm must be corrected because of mokto projection. In mokto projection, the distance between the two parallel lines is not balanced. Therefore, the angle depicted by a tile depends on the vertical position.
The followingCodeCalculate the vertical position based on the latitude:
Code:
/** <Summary> get the vertical tile number from a latitude
Using Mercator projection 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 should be from-90 to 90, but because of the existence of mocato projection, the pole is projected to the Infinity point, so the coverage area is less than-90 to 90.
[Protection]
Google map uses a protection mechanism to ensure the quality of the server. If an IP address has too many requests, it will be added to the blacklist and prompt a friendly message :(
Quote:
Google Error
We're sorry ...... but your query looks similar to automated requests from a computer virus or spyware application. to protect our users, we can't process your request right now. we'll restore your access as quickly as possible, so try again soon. in the meantime, if you suspect that your computer or network has been infected, you might want to run a virus checker or spyware remover to make sure that your systems are free of viruses and other spurious software. we apologize for the inconvenience, and hope we'll see you again on Google.
To avoid being blacklisted, developers shoshould use a caching mechanic if possible...
[Example]
Global image URL, http://kh0.google.com/kh? N = 404 & V = 8 & t = T
The four quadrants are as follows: (Note that the names of the four servers are used for load balancing)
Http://kh0.google.com/kh? N = 404 & V = 8 & t = TQ
Http://kh1.google.com/kh? N = 404 & V = 8 & t = tr
Http://kh2.google.com/kh? N = 404 & V = 8 & t = TS
Http://kh3.google.com/kh? N = 404 & V = 8 & t = TT
(After processing the four images, merge them into one)
Attachment:/files/dotnetdoor/googlemapcs.rar
Article 2:[Source code] how to use Google map resources in your program (2)-geographic coordinates of region names
Original address: http://bbs.msproject.cn/default.aspx? G = posts & t = 223
[Translation]
Pascal buirey by how Google map works (Part2): The geocoder
How to use Google geocoder to obtain the geographic coordinates of a region name
[Introduction]
After finding out how to obtain images through geographic coordinates (any use of Google map resource ×× link ×× in your program), I would like to study the function of the next Google map: geocoder. Geocoder is a service that allows you to obtain the coordinates (longitude and latitude) of a region by region name ). This article will explain this to you.
[URL request]
To request coordinates from Google, you need to construct a "question" That Google can recognize ". The question URL can be expressed as follows:
Code:
Http://maps.google.com/maps? Output = kml & Q = my street name
The http://maps.google.com/maps will submit your requestGeocoderService, the output = kml parameter tells Google to give a simple and understandable answer. The q = my_street_name parameter indicates where you need information.
[Google answer]
I found two possible answers: if the region name is accurate, Google will send you its coordinates. If Google needs a more precise location, it will send you a list of region names, and then you must select a value in the list and request again. The XML file of the final answer is as follows:
Code:
<? XML version = "1.0" encoding = "UTF-8"?>
<Kml xmlns = "http://earth.google.com/kml/2.0">
<Placemark>
<Name> New York, NY </Name>
<Address> New York, NY </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
<Point>
<Coordinates>-74.007130, 40.714490, 0 </coordinates>
</Point>
<Lookat>
<Longpolling>-74.007130 </longpolling>
<Latitude> 40.714490 </latitude>
& Lt; range & gt; 64586.917969 & lt;/range & gt;
</Lookat>
</Placemark>
</Kml>
If Google needs a more accurate name, the resulting XML will be:
Code:
<? XML version = "1.0" encoding = "UTF-8"?>
<Kml xmlns = "http://earth.google.com/kml/2.0">
<Folder>
<Name> did you mean: </Name>
<Open> </Open>
<Placemark>
<Name> Paris, Lamar, Texas, United States </Name>
<Address> Paris, Lamar, Texas, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, Henry, Tennessee, United States </Name>
<Address> Paris, Henry, Tennessee, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, Edgar, Illinois, United States </Name>
<Address> Paris, Edgar, Illinois, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, bourbon, Kentucky, United States </Name>
<Address> Paris, bourbon, Kentucky, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, Logan, Arkansas, United States </Name>
<Address> Paris, Logan, Arkansas, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, Monroe, Missouri, United States </Name>
<Address> Paris, Monroe, Missouri, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, mecosta, Michigan, United States </Name>
<Address> Paris, mecosta, Michigan, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, Bear Lake, Idaho, United States </Name>
<Address> Paris, Bear Lake, Idaho, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, Stark, Ohio, United States </Name>
<Address> Paris, Stark, Ohio, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
<Placemark>
<Name> Paris, Lafayette, Mississippi, United States </Name>
<Address> Paris, Lafayette, Mississippi, United States </address>
<Styleurl> root: // stylemaps # default + nicon = 0x304 + hicon = 0x314 </styleurl>
</Placemark>
</Folder>
</Kml>
The example in this article is written in C # And allowed in. NET Framework.
Attachment:
/Files/dotnetdoor/googlegeocoder.rar