142 google maps
# %pip install -U geemap
To use Google Maps as basemaps, you need to sign up for a Google Maps API key. Follow the instructions on the Google Maps Platform website to get an API key. The following steps are required:
- Step 1: Set up a Google Cloud project
- Step 2: Enable Google Maps Platform APIs and SDKs
- Step 3: Get an API key
There is a cost for requesting Maps tiles, but there is a $200 monthly credit and we've been told that for the purposes of typical EE-type usage, it would be rare to exceed $200.
Once you have your API key, you can set it as a Google Colab secret with the name GOOGLE_MAPS_API_KEY
. Alternatively, you can set it as an environment variable on your local machine. Uncomment the following line to set the environment variable if you are running this notebook locally.
# import os
# os.environ["GOOGLE_MAPS_API_KEY"] = "<YOUR-API-KEY>"
Import libraries
import ee
import geemap
If the GOOGLE_MAPS_API_KEY
environment variable is set, geemap will automatically detect it and use it to request Google Maps tiles. By default, geemap will use Google Roadmap as the basemap.
m = geemap.Map()
m
Use Google Hybrid basemap.
m = geemap.Map(basemap="Google.Hybrid")
m
To use multiple basemaps, you can use the Map.add_basemap()
function.
m = geemap.Map()
m.add_basemap("Google.Hybrid")
m
Use Google Satellite basemap.
m = geemap.Map(basemap="Google.Satellite")
m
Use Google Terrain basemap.
m = geemap.Map(basemap="Google.Terrain")
m
Google Maps can be customized with various parameters. To create a custom Google Maps basemap, you can use the GoogleMapsTileProvider
class. See https://bit.ly/3UhbZKU for more information on the available parameters.
from geemap.basemaps import GoogleMapsTileProvider
style = [
{"stylers": [{"hue": "#00ffe6"}, {"saturation": -20}]},
{
"featureType": "road",
"elementType": "geometry",
"stylers": [{"lightness": 100}, {"visibility": "simplified"}],
},
]
m = geemap.Map(center=[40, -100], zoom=4)
basemap = GoogleMapsTileProvider(
map_type="roadmap",
region="CN",
language="zh-Cn",
scale="scaleFactor2x",
highDpi=True,
style=style,
)
m.add_basemap(basemap)
m