gmplot

1.4.1 · active · verified Thu Apr 16

gmplot is a Python library providing a matplotlib-like interface to plot geographical data on Google Maps. It allows users to easily add markers, heatmaps, polygons, and other visualizations to generate interactive HTML maps. The library is actively maintained; its current version, 1.4.1, includes features like draggable markers and ground overlays.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic Google Map, add a marker, scatter a few points, and save the result as an interactive HTML file. It highlights the use of `GoogleMapPlotter` and the importance of including an API key for full functionality. The generated HTML file can be opened in a web browser to view the map.

import gmplot
import os

# Replace with your actual coordinates and zoom level
latitude, longitude, zoom = 37.4239163, -122.0946215, 16

# Initialize GoogleMapPlotter with center latitude, longitude, and zoom
# Add your Google Maps API key using os.environ.get('GOOGLE_API_KEY', '')
# to avoid the 'For Development Purposes Only' watermark
gmap = gmplot.GoogleMapPlotter(latitude, longitude, zoom, apikey=os.environ.get('GOOGLE_API_KEY', ''))

# Add a marker
gmap.marker(latitude, longitude, 'cornflowerblue', size=40, title="My Location")

# Add a scatter plot (e.g., nearby points)
more_lats = [37.425, 37.420]
more_lngs = [-122.090, -122.100]
gmap.scatter(more_lats, more_lngs, '#FF0000', size=20, marker=False)

# Draw the map to an HTML file
output_html_file = 'mymap.html'
gmap.draw(output_html_file)

print(f"Map saved to {output_html_file}")

view raw JSON →