solarpy.plotting.plot_google_maps

solarpy.plotting.plot_google_maps#

solarpy.plotting.plot_google_maps(latitude, longitude, api_key, zoom=20, map_type='satellite', size=(400, 400), ax=None)#

Fetch a Google Maps Static image and render it on a Matplotlib Axes.

Queries the Google Maps Static API to retrieve a map image centered on the given coordinates and renders it using ax.imshow. A crosshair marker is overlaid when zoomed out (zoom < 20) to indicate the center point.

Parameters:
  • latitude (float) – Latitude of the map center, in decimal degrees. Must be in [-90, 90].

  • longitude (float) – Longitude of the map center, in decimal degrees. Must be in [-180, 180].

  • api_key (str) – Google Maps Static API key.

  • zoom (int, optional) – Zoom level between 0 (world) and 21 (building). Default is 20.

  • map_type (str, optional) – Map rendering style. One of "roadmap", "satellite", "terrain", or "hybrid". Default is "satellite".

  • size (tuple, optional) – Width and height of the requested image in pixels. Default is (400, 400).

  • ax (matplotlib.axes.Axes, optional) – Axes to draw on. If None, a new figure and axes are created.

Returns:

  • fig (matplotlib.figure.Figure) – The figure containing the map.

  • ax (matplotlib.axes.Axes) – The axes containing the rendered map image.

Raises:
  • requests.HTTPError – If the API returns a non-2xx status code (e.g. 403 for an invalid API key, 400 for bad parameters).

  • requests.Timeout – If the request exceeds the 10-second timeout.

Return type:

tuple[Figure, Axes]

Notes

A white crosshair ('w+') is plotted at the image center when zoom < 20, where individual features are too small to locate the center point visually.

Examples

Plot a satellite view of Copenhagen:

>>> import solarpy
>>> solarpy.plotting.plot_google_maps(
...     55.6761, 12.5683, api_key="YOUR_KEY", zoom=12)