Moment For Technology

Google Map tile download

Posted on Aug. 10, 2023, 10:02 a.m. by Donna Morgan
Category: node.js Tag: node.js google-maps

Google Map tile download

All kinds of map downloader to spend money, but too poor to write their own.


Tiles address gl = CNhl = {type} {language} x = {x} y = {} y z = {} z

Parameters that

  • Lyrs = type

    • h = roads only
    • m = standard roadmap
    • p = terrain
    • r = somehow altered roadmap
    • s = satellite only
    • t = terrain only
    • y = hybrid
  • GL is the coordinate system

    • CN = Chinese Mars coordinate system
  • HL = Map Text Language

    • Useful - CN = Chinese
    • En - US = English
  • X is equal to the horizontal of the tile
  • Y is equal to the vertical of the tile
  • Z = zoom level satellite map 0-14, roadmap 0-17

Calculate the coordinates of XYZ

Google Maps uses a Mercator projection, just remember that, because you'll need it when you're working with maps.

Assuming that longitude = LNG, latitude = LAT and zoom level is ZOOM at a certain point, then the corresponding tile coordinates are:

// The total number of tiles in the global map n = 2 ^ zoom; Floor ((LNG + 180.0/360.0) * n); Floor ((LNG + 180.0/360.0) * n); // The current coordinate of the tile is y // -90°~90°, unevenly divided n tangent = Math.tan (Toradians (Lat)); sec = math.sec(toRadians(lat)); y = math.floor((1 - (math.log(tan + sec) / math.pi)) / 2 * n);

When downloading the map, take 2 diagonal longitude and latitude coordinates of a rectangular area, calculate the tile coordinates according to the above formula, visit the tile download address to download and save the picture.

Watch out (pit!)

Horizontal and vertical range of tiles is 0 ~ 2^ Zoom, level 1 1x1, level 2 2x2, level 3 4x4...

It is suggested to download satellite map and road map respectively, and display them in layers in the map display control, so that different contents can be selectively displayed.

About (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.