google-maps-api-3geoxml3event-triggers

Can't get google.maps.event.trigger(geoXml.docs[0].placemarks[0].marker,'click') to work


I want an infowindow to open automatically when this map is loaded. I'm trying to apply the very fine answer here, the only difference I can see being that I'm triggering a click on a marker rather than on a polygon. I've been staring at and fiddling with the code for a while but just can't get it to trigger that click. What am I missing?

Thanks, Drew

This pared-down version is using a KML file with one placemark. The relevant code for the event.trigger is down at line 33.

<!DOCTYPE html>
<html>
<head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
        html, body, #map-canvas {
            height: 100%;
            margin: 0px;
            padding: 0px
        }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>
    <script src="http://geoxml3.googlecode.com/svn/trunk/ProjectedOverlay.js"></script>
    <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDDFrP7MSD1ieFEvaF95BRlwHa0S72Fy1s&sensor=FALSE"></script>
    <script>

        function initialize() {
            var mapOptions = {
                zoom: 6,
                center: new google.maps.LatLng(47.606209, -122.332069)
            };
            var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions );

            var blues = new geoXML3.parser({map: map, zoom: false});
            blues.parse('allbluesdance_seattle.kml');

            google.maps.event.addListenerOnce(map, 'idle', function(){
                alert("Clicking now.");
                google.maps.event.trigger(geoXml.docs[0].placemarks[0].marker,'click')
            });

        }

        google.maps.event.addDomListener(window, 'load', initialize);

    </script>
</head>
<body>
    <div id="map-canvas"></div>
</body>
</html>

Solution

  • You have a javascript error in your code: Uncaught ReferenceError: geoXml is not defined (because geoXml is undefined). That should be blues in your code.

        function initialize() {
            var mapOptions = {
                zoom: 6,
                center: new google.maps.LatLng(47.606209, -122.332069)
            };
            var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    
            var blues = new geoXML3.parser({
                map: map,
                zoom: false
            });
            blues.parse('allbluesdance_seattle.kml');
    
            google.maps.event.addListenerOnce(map, 'idle', function () {
                alert("Clicking now.");
                google.maps.event.trigger(blues.docs[0].placemarks[0].marker, 'click');
            });
    
        }
    
        google.maps.event.addDomListener(window, 'load', initialize);
    

    working fiddle