-1

我希望在加载此地图时自动打开一个信息窗口。我试图在这里应用非常好的答案,我能看到的唯一区别是我触发了对标记而不是多边形的点击。我一直盯着并摆弄代码一段时间,但无法让它触发点击。我错过了什么?

谢谢,德鲁

此精简版使用带有一个地标的 KML 文件。event.trigger 的相关代码位于第 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>
4

1 回答 1

0

您的代码中有一个 javascript 错误:(Uncaught ReferenceError: geoXml is not defined因为 geoXml 未定义)。那应该blues在您的代码中。

    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);

工作小提琴

于 2014-07-18T22:50:25.487 回答