Folium-style Python helpers for rendering Google Maps.
Project description
gmaprium
Folium-style Python helpers for rendering Google Maps HTML.
gmaprium can be used to create standalone HTML maps, display maps in Jupyter Notebook, add Google tile layers to existing Folium maps, and embed maps in Streamlit apps.
Installation
pip install gmaprium
Usage
from gmaprium import GeoJson, HeatMap, LayerControl, Map, Marker, Polygon
m = Map(
location=[35.6812, 139.7671],
zoom_start=12,
api_key="YOUR_GOOGLE_MAPS_API_KEY",
map_type="roadmap",
height="500px",
)
Marker([35.6812, 139.7671], popup="Tokyo Station", tooltip="Tokyo", name="Stations").add_to(m)
Polygon(
[[35.70, 139.70], [35.70, 139.82], [35.62, 139.82], [35.62, 139.70]],
name="Area",
).add_to(m)
HeatMap([[35.6812, 139.7671, 2], [35.6895, 139.6917, 1]], name="Heat").add_to(m)
LayerControl().add_to(m)
# Full HTML document.
m.save("map.html")
# Embeddable HTML fragment for web apps.
html = m.render_fragment()
You can also pass the API key with the GOOGLE_MAPS_API_KEY environment variable.
Markers use Google's AdvancedMarkerElement. If you add markers without passing map_id=..., the renderer uses Google's DEMO_MAP_ID for local testing.
Supported Elements
MapMarkerPolylinePolygonCircleGeoJsonHeatMapLayerControl
GeoJson accepts GeoJSON dictionaries, JSON file paths, objects with __geo_interface__, and GeoPandas-like objects with to_json().
HeatMap uses a canvas overlay instead of Google's deprecated JavaScript HeatmapLayer.
It ports the Leaflet.heat/simpleheat rendering model, including radius, blur, min_opacity, max_zoom, max_value, and gradient.
The defaults match Leaflet.heat/simpleheat on a typical OSM map: radius=25, blur=15, min_opacity=0.05, max_zoom=18, max_value=1.0, and the blue-cyan-lime-yellow-red gradient.
Lower zoom levels are intentionally faded by Leaflet.heat's max_zoom - zoom intensity scale. Set max_zoom closer to your initial zoom if the heat fades too quickly.
The legacy google_tiles_url() and add_google_tiles() helpers are still available for projects that want to add Google tile URLs to an existing Folium map.
Notebook
In Jupyter Notebook, display the map by returning the Map object as the last expression in a cell.
import os
from gmaprium import HeatMap, LayerControl, Map, Marker
os.environ["GOOGLE_MAPS_API_KEY"] = "your-api-key"
m = Map(location=[35.6812, 139.7671], zoom_start=12, height="500px")
Marker([35.6812, 139.7671], popup="Tokyo Station", name="Markers").add_to(m)
HeatMap([[35.6812, 139.7671, 1.0]], name="Heat", max_zoom=14).add_to(m)
LayerControl().add_to(m)
m
You can also display explicitly:
from IPython.display import HTML, display
display(HTML(m.render_fragment()))
The notebook example is available at examples/example.ipynb.
Folium Extension
If you already use Folium, add Google tile layers to a folium.Map with add_google_tiles().
import folium
from gmaprium import add_google_tiles
m = folium.Map(location=[35.6812, 139.7671], zoom_start=12, tiles=None)
add_google_tiles(m, api_key="your-api-key", map_type="roadmap", name="Google Roadmap")
add_google_tiles(m, api_key="your-api-key", map_type="satellite", name="Google Satellite", show=False)
folium.LayerControl().add_to(m)
m.save("folium_google_tiles.html")
This Folium extension only adds Google tile layers. It does not enable the Google Maps JavaScript API renderer or gmaprium's HeatMap.
The Folium example is available at examples/folium_extension.py.
Streamlit
Use st_google_map() to render a gmaprium.Map inside a Streamlit app.
import os
import streamlit as st
from gmaprium import Map, Marker, st_google_map
api_key = os.environ["GOOGLE_MAPS_API_KEY"]
m = Map(location=[35.6812, 139.7671], zoom_start=12, api_key=api_key, height="600px")
Marker([35.6812, 139.7671], popup="Tokyo Station").add_to(m)
st_google_map(m)
Install the optional dependency and run the example app:
python -m pip install -e ".[dev,streamlit]"
export GOOGLE_MAPS_API_KEY="your-api-key"
streamlit run examples/streamlit_app.py
The Streamlit example is available at examples/streamlit_app.py.
Development
python -m pip install -e ".[dev]"
pytest
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmaprium-0.1.0.tar.gz.
File metadata
- Download URL: gmaprium-0.1.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7065f8bf9d9a098cec5e7ef4bc38373b102f4803e53d9ba561a038186d577c18
|
|
| MD5 |
ab5e482715ea97c7cc1a8315ae1849a8
|
|
| BLAKE2b-256 |
cd568f658f3020d1c1a3277e60f43e2686eac1efce1c679bc29888ac64c3cee8
|
File details
Details for the file gmaprium-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gmaprium-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ca5b0751324deb488c4cca26bd3483e2c2e3449e9e19f2d5894cdac608b1bd8
|
|
| MD5 |
c7c49915f70a5102a8fbfe6beb2d9168
|
|
| BLAKE2b-256 |
69012ce2d81118fc0a550269e9db1f629733bafa5625de364e67cd614ffdbfb1
|