google maps

by Garth Edwards

HTML

<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
<script src="https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/src/infobubble.js"></script>
<div id="map_canvas"></div>

CSS

html, body, #map_canvas {
    width:100%;
    height:100%;
}

JavaScript

var map;
var infoBubble;

// Initial position of the map
var center = new google.maps.LatLng(-25.363882, 131.044922);

function initialize() {
    // Map options
    var mapOptions = {
        zoom: 4,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    // Attach the map to the document
    map = new google.maps.Map(document.getElementById('map_canvas'),
    mapOptions);
    // The marker
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(-25.363882, 131.044922),
        map: map,
        title: 'marker7'
    });

    infoBubble = new InfoBubble({
        maxWidth: 450,
        minWidth: 450,
        maxHeight: 165,
        minHeight: 165,
        backgroundColor: 'rgba(65,65,65,0.7)',
        disableAnimation: true,
        content: '<div><a class="dialog" href="https://maps.google.com/" target="_blank"></a></div>',
        position: new google.maps.LatLng(-34.397, 150.644)
    });


    google.maps.event.addListener(marker, 'click', function () {
        	console.log('marker just clicked');
        infoBubble.open(map, marker);
        	console.log('line after infoBubble.open');
        google.maps.event.addListener(infoBubble, 'domready', function () {
			setTimeout(function() {
                    console.log('inside domready function');
                $.get('https://lh4.googleusercontent.com/-_Cox6aEnSkU/UQ_B0LK4khI/AAAAAAAAAzw/4H4dsWGPgeE/s150/go-button.png', function (myImage) {
                        console.log('just got the external image, now let\'s add something completely unrelated...');
                    $(".dialog").html('<img id="theImg" src="https://goo.gl/phmzis" />');
                        console.log('apparently that was added, but i don\'t see it on first click');
                })
            }, 50);			// vary the timeout duration - minimum I found worked was 5 ms - but you'll have to use significantly more for slower systems
        });
   ...