Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export interactive google map as a static image

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

like image 840
Harshdeep Avatar asked Mar 20 '17 16:03

Harshdeep


People also ask

Is Google Maps static free?

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.

Is Google map dynamic or static?

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.


2 Answers

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.

like image 150
Downhillski Avatar answered Sep 25 '22 02:09

Downhillski


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

enter image description here

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.

like image 32
Pascal Bugnion Avatar answered Sep 22 '22 02:09

Pascal Bugnion