Print a Google map with directions to it

I have a google map on my webapp - working with JavaScript API V3. I give my users the ability to manage certain routes using the directions of a Google map. Now my problem is that I want to give them the opportunity to print it (just a map, not the whole site).

I tried the following:

var OpenWindow = window.open("_blank", "", ''); var contents = document.getElementById("mapMainCanvas"); OpenWindow.document.write(contents.innerHTML); 

This really opens a new tab with a map, but without directions. In addition, I could not find the "print" option in the API. Has anyone solved this problem?

Thanks.

+4
source share
2 answers

Try the following:

 var content = document.getElementByID('mapMainCanvas'); //has to be first. var win = window.open(); win.document.write(content); win.print(); win.close(); 

I hope this works!

(Please let me know if this is the case or not.)

+4
source

Could you create a print stylesheet and use CSS to render only the map, hiding everything else? You may need to play with classes using jQuery / other if you want users to be able to print this page as usual.

You can find instructions on getting started with print style sheets here: http://coding.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/

0
source

All Articles