Design and implementation of Google Map downloader for C # edition

Source: Internet
Author: User

about how to convert the earth latitude and longitude coordinate system into a program commonly used in the plane 2D coordinate system, many articles on the Internet, refer to http://www.cnblogs.com/beniao/archive/2010/04/18/1714544.html (this article 1 Figure 3 from here). Google Maps uses the "Mercator projection method" (wikipedia URL http://en.wikipedia.org/wiki/Mercator_projection), which presumably means putting the earth in a cylinder, Let the Earth's equator and the cylinder wall contact, put a lamp in the center of the Earth, the image on the earth will have a shadow on the cylinder wall, and then expand the cylinder wall, resulting in a "rectangular map" is converted to the plane 2D map, the description is very simple, the actual expansion of the map has also carried out other processing.

Figure 1

It can be imagined that the longitude on the earth after the illumination of the light, the shadow generated on the cylinder wall should be uniform step, and latitude is not the same, latitude after the light irradiation, the closer the equator distribution more dense, the farther away from the equator the more sparse, to the Earth's Poles (Antarctica and the Arctic), will tend to infinity, So Google Maps does not contain the Earth's polar regions (north to latitude 85 degrees, south to latitude 85 degrees, presumably).

Google Maps contains the Earth's longitude: 0 degrees east longitude 180, 0 degrees ~ West Longitude 180 (total 360 degrees), Latitude: 0 degrees ~ Latitude 85,0 degrees ~ South Latitude 85 (total 170 degrees). Note: The above 0 longitude is indicated by the British prime meridian, 0 latitude refers to the equator. converted to a planar 2D graph, the origin (0,0) in the upper left (consistent with the program), in pixels as a unit, so that any point on the earth (longitude, latitude) can be converted to a planar 2D coordinate system of a point (x, y), the conversion algorithm has been provided, directly can be used. As mentioned above, the latitude and longitude in the cylindrical wall of the shadow step density is different, latitude away from the equator step more dilute, therefore, although the longitude range is 360 degrees ( -180~180, west longitude is negative, East is positive, from western to Eastern, latitude more and more large), far greater than latitude 170 degrees ( -85~85, south latitude is negative, North latitude is positive), but the length and width of the image generated after mapping to the cylinder wall is equal (this also has the reason for later processing), in essence, the Google Map's length and width are indeed the same.

Because the map can be zoomed out, so the map is not possible to use the same picture, so the amplification will be distorted, Google Maps is the practice of the map to pre-defined zoom level (level 0 ~22, commonly used 0~17), each zoom level corresponds to a lot of small square pictures (called tiles), These small squares are 256*256 pixels, and then the tiles are stitched together to create a large, clear map. The zoom level of Google Maps has a corresponding relationship with the number of tiles: The number of tiles =2 n times the nth square (n is the zoom level). That is, when the zoom level is 0 o'clock, the entire world map only 1*1 the graph of 256*256, when the zoom level is 1, the entire world map contains a graph of 2*2 256*256 size, and when the zoom level is 2, the entire world map contains a map of 4*4 size 256*256. For a zoom level of 0 o'clock, the coordinate corresponds to the relationship:

Figure 2

When the zoom level changes, the entire world map is composed of changes such as:

Figure 3

Google Maps background display principle is to download the tiles under each zoom level, and then splicing together, if we know how to download tiles, then we can also simulate a similar Google Map display interface. Here's a demo showing how to download tiles of the two-point containing area based on the two latitude and longitude points (upper-left corner, bottom-right corner), and zoom level, and then stitch together.

Demo do not do too much explanation, the code comments in detail, note the points:

    • Google Maps provides an API to download tile columns, rows, and zoom levels through HTTP requests,

Domestic Address: Http://mt0.google.cn/vt/[email protected]&hl=zh-cn&gl=cn&src=app&x=0&y=0&z=0

Foreign address: http://mts0.googleapis.com/vt?lyrs=m&x=0&y=0&z=0

Where the address in front of the mt0 can be MT1, MT2, MT3, respectively, for different servers, corresponding, MTS0 can be mts1, mts2, Mts3. x, y, and z represent the tile's column number, line number, and zoom level, respectively.

lyrs represents the map type:

M: Road Map

T: Topographic map

P: Tagged topographic map

S: Satellite map

Y: Tagged satellite map

    • The latitude and longitude of the top left and bottom right corner of the demo are ( -180~180) and ( -85~85) respectively, and the longitude of the upper left corner must be less than the longitude of the lower right corner, the upper left corner must be greater than the latitude of the lower right corner, as for why, the reason is must be able to determine a region through these two points No judgment is given in the demo program.
    • Do not select the area is too large, or the zoom level is too large, because it contains too many tiles to download, the program did not do any performance optimization, there may be a bug. The thread should not be too much, but too much slower. If the download image has failed, you can download it several times, you can complete, such as only download the last failed image.
    • The demo is similar to Google Map and other maps. I used the actual project to download from the Google Map of these tiles, imitating the Google map display principle to do a map display module.

Figure 4 Demo Main interface

Figure 5 Download completed tiles

Figure 6 tiling tiles into a large picture

Source: Http://files.cnblogs.com/xiaozhi_5638/GoogleMapDownLoader.rar

VS2010 Win7 Debugging pass, hope to have help!

Zhou Chihi
Source: http://www.cnblogs.com/xiaozhi_5638/
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility. C#

C # version of Google Map Downloader design and implementation

Related Article

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.