为什么Marker Manager不起作用?

时间:2012-01-03 21:26:58

标签: google-maps-api-3 javascript

我会使用MarkerManager将相邻标记组合在一起,我测试了一个例子,但它不起作用。不同的标记显示得很好,但它们应该在一起时不在一起。经理没有按照自己的意愿工作,我不明白为什么。

<html>
<head>
    <title>Test GMap - MarkerManager</title>
    <script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/1.0/src/markermanager.js"></script>
    <script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js"></script>
</head>

<body>
    <div id="my-map" style="width:100%;height:700px"></div>
    <script>
        var maCarte = '';
        function initialisation(){
            var centreCarte = new google.maps.LatLng(47.389982, 0.688877);
            var optionsCarte = {
                        zoom: 5,
                        center: centreCarte,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    }
            maCarte = new google.maps.Map(document.getElementById("my-map"), optionsCarte);
            // Create a new instance of the MarkerManager
            var mgr = new MarkerManager(maCarte);
            google.maps.event.addListener(mgr, 'loaded', function() {
                console.log('loaded Map');
                // Create marker array
                var markers = [];
                // Loop to create markers and adding them to the MarkerManager
                for(var i = 0; i < 50; i += 0.1) {
                    var marker = new google.maps.Marker({position: new google.maps.LatLng(47.389982 + i, 0.688877 + i)});
                    markers.push(marker);
                }
                //var markerCluster = new MarkerClusterer(map, markers);
                // Add the array to the MarkerManager
                mgr.addMarkers(markers, 8);
                // Refresh the MarkerManager to make the markers appear on the map
                mgr.refresh();
            });
        }

        google.maps.event.addDomListener(window, 'load', initialisation); 
    </script>
</body>

有人可以帮助我吗?

非常感谢

1 个答案:

答案 0 :(得分:1)

您的页面适合我,但页面加载时标记不会立即显示。这是因为第34行的缩放设置:

mgr.addMarkers(markers, 8);

如果将其设置为较小的数字(例如,4),则在进一步缩小时将显示标记。

相关问题