I know this post is outdated, but I thought it might be useful if someone stumbles upon this and is looking for a more recent example. Although the code in the answer works well, it is not written in jQuery friendly format. I also found that the way to configure event listeners made it a little harder to use. Finally, a fixed card size just doesn't work in the modern world. Hope this helps someone!
Add #mapHolder anywhere on your page and customize it to your liking:
<div id='mapHolder' style='whatever you want'></div>
Place links anywhere on your page so that you display a map when you shade:
<a class="mapthis" place="properly formatted address" zoom="12">MAP</a>
JQuery
$(document).on("mouseenter", ".mapthis", function(e) { var desiredMapWidthPercent = .8; var mapWidth = Math.round($(window).width() * desiredMapWidthPercent); var aspectRatio = mapWidth / $(window).height(); var mapHeight = Math.round($(window).height() * aspectRatio); var boxWidth = mapWidth; var boxHeight = mapHeight; var scale = 1; var pZoom = parseInt($(this).attr("zoom")); var pPlace = $(this).attr("place"); if((mapHeight > 640) || (mapWidth > 640)){ mapHeight = Math.round(mapHeight / 3.5); mapWidth = Math.round(mapWidth / 3.5); scale = 2; if(((mapHeight) > 1280) || ((mapWidth) > 1280)){ mapHeight = 640; mapWidth = 640; boxWidth = 1280; boxHeight = 1280; }else{ boxWidth = mapWidth * 2; boxHeight = mapHeight * 2; } } var fromleft = Math.max(0, ((($(window).width() - boxWidth) / 2) + $(window).scrollLeft()))+'px'; var fromtop = Math.max(0, ((($(window).height() - boxHeight) / 2) + $(window).scrollTop()))+'px'; var pText = $(this).html(); $('#mapHolder').html('<a href="https://maps.google.com/maps?q=' + pPlace + '&z=11" target="new"><img border=0 src="https://maps.google.com/maps/api/staticmap?center=' + pPlace + '&zoom=' + pZoom + '&size='+mapWidth+'x'+mapHeight+'&scale='+scale+'&sensor=false&format=png&markers=color:blue|' + pPlace + '"></a>'); $('#mapHolder').css({position:'absolute',top:fromtop,left:fromleft, width:boxWidth, z-index:'999'}); $('#mapHolder').show(); }); $(document).on("mouseleave", ".mapthis", function(e) { if($(e.relatedTarget).closest('#mapHolder').length){ $("#mapHolder").on("mouseleave", function(e) { $('#mapHolder').hide(); }); return; } $('#mapHolder').hide(); });
source share