HiMap is a console application that allows you to download Google Maps with custom styling, with any supported zoom and at any size. The program is written in Python and relies on the Google Maps Static API, through which it sequentially requests parts of the map and then uses the PIL library to assemble them into one large image.
The user specifies the map coordinates (or one coordinate and the total size), zoom level, map style, and enters their API key. The result is a map matching the requirements stored in PNG.
You can use Snazzy Maps to style the map and then download the style as a JavaScript Style Array
directly from the SM editor.
The resulting map has size of width*640 x height*614
px.
Unfortunately, the Earth is not flat, so we have to accept that linear approximations do not work in extreme cases. This approach breaks around the poles, for example, but works perfectly for countries in Europe.
The script is controlled from the command line. You need to have Python 3.11
or higher installed. After cloning the repository from GitHub, we first create a virtual environment and install the necessary packages using commands:
# creating venv:
python -m venv .venv
# venv activation:
# linux
source .venv/bin/activate
# windows cmd
.venv/Scripts/activate.bat
# windows PS
.venv/Scripts/Activate.ps1
# installing requirements:
pip install -r requirements.txt
# run the script
python3 -m himap output_path optional_params
output_path
- the result will be stored here
--start X Y
- where
X
andY
are the latitude and longitude in degrees of the upper left corner of the map X
andY
arefloat
- where
--end X Y
- where X and Y are the latitude and longitude in degrees of the bottom right corner of the map
X
andY
arefloat
--width X
- map width as the number of squares that make up the final map
X
isuint
--height X
- map height as the number of squares that make up the final map
X
isuint
- these parameters can be used for debugging (for example, to check the alignment of map pieces:
--width 2 --height 2
)
-z X, --zoom X
- Google Maps zoom level, determines the zoom of the map
X
isunint
,0 <= X <= 19
--style path_to_style
- path to
JSON
with styling to be used on the map
- path to
--save
- if this flag is set, all parts of the map that the script pulls from the Google server during runtime are saved in the same directory as the final map
--key api_key
- the API key is needed to communicate with the Google server, each user has their own
--store
- saves the specified API key for further use
- there is no need to enter the key when the script is run again, it reads it itself from the created
TXT
file
Since it is significantly easier to crop the map than to struggle with shifting coordinates because of a few pixels, a padding is added around the specified coordinates, from 320 to around 640 px.
Downloading, caching and similar usage of Google Maps violates the TOS, therefore I disclaim any liability arising from the use of this program. More at Google Maps TOS, to be more specific: paragraph 3.2.3 a)
.
The stored API key is not encrypted in any way, it is saved as plain text in the directory from which the script is run. It is therefore visible to everyone who has access to the folder.