I am creating certain heatmaps using gmaps which is a jupyter extension. The output of this library are interactive google maps like one here.
I want the final output to be a png image which should be obtainable via google static maps but I don't know how do I convert a map with an extra layer of heatmap to a static map programatically.
Is it possible to convert a map like this to a static image.
Thanks
The Maps Static API uses a pay-as-you-go pricing model. Requests for the Maps Static API are billed under the SKU for Static Maps. Along with the overall Google Terms of Use, there are usage limits specific to the Maps Static API. Manage your costs and usage with tools available in the Google Cloud Console.
Since the map produced is a static image, it won't be interactive or tailored to the user but it can be stylised through the custom parameters.
If you need a heatmap, you can't solely relies on the static map api, you will either grab the tiles from using a Google Maps API for JavaScript and lay them out in your canvas or container or a backend service or use some other heatmap libraries to output the layer in the same projection that you use for Google Maps API (defaults to Web Mercator) as a PNG and overlay on top your static map image.
Somewhat late to the party, but I'm the author of gmaps, the jupyter widget mentioned in the question.
You can now export PNGs from gmaps
:
$ pip install -U gmaps
$ jupyter nbextension enable --py --sys-prefix gmaps
You can then create a map with an export button:
import gmaps
gmaps.__version__ # => 0.4.2.rc3
gmaps.configure(api_key="...")
fig = gmaps.figure()
fig.add_layer(gmaps.heatmap_layer([(50.0, 5.0), (52.0, 6.0)]))
fig
If you click the download button, it will export the map to a PNG.
For limitations, read the documentation
For reference, the static API is not well suited for maps with significant amounts of data overlaid (as would be typical for heatmaps), since there is an upper limit to the amount of data that the API accepts. Currently this is limited to 8192 bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With