I am looking for a method to efficiently print Google maps that have been implemented on a site using the google maps api v3.
I have seen some people using just the
You can use html2canvas.js to convert map div to canvas element, then you can print it as image. Below code works perfect for me:
HTML
JavaScript
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: defLocation,
mapTypeId: 'satellite',
streetViewControl: false
});
$(document).on('click', '.printBtn', function () {
map.setOptions({
mapTypeControl: false,
zoomControl: false,
streetViewControl: false,
panControl: false
});
var printWin = window.open('', '', 'width=1000,height=700');
var windowContent = '';
html2canvas($("#map"), {
useCORS: true,
onrendered: function (canvas) {
windowContent += ''
windowContent += 'Print canvas ';
windowContent += ''
windowContent += '
';
windowContent += '';
windowContent += '';
printWin.document.open();
printWin.document.write(windowContent);
printWin.document.close();
printWin.focus();
setTimeout(function () { printWin.print(); printWin.close(); }, 500);
map.setOptions({
mapTypeControl: true,
zoomControl: true,
streetViewControl: true,
panControl: true
});
}
});
});