0

I have problem adding markers into marker Clusterer of Google Maps. Firebug returns error:

Error: Invalid value for property : [object Object]' when calling method: [nsIDOMEventListener::handleEvent]

Markers are created with mix of JavaScript and PHP:

// loop starts here.......

    var randLatLng = new google.maps.LatLng( <?php echo $lat; ?>, <?php echo $lon; ?> );
    var marker_<?php echo $gauging["Gauging"]["id"]; ?> = new google.maps.Marker({
        map: MyMap.map,
            title: '<?php echo $gauging["Gauging"]["identification"]; ?>',
            position: randLatLng,
            draggable: false, 
            clickable: true, 
            icon: '/img/markers/yellow_Marker.png',
            myId: 'gp_<?php echo $gauging["Gauging"]["id"]; ?>'
        });
    myMap.markers.push(marker_<?php echo $gauging["Gauging"]["id"]; ?>);

// loop ends here .......

var markerYellowCluster = new MarkerClusterer(myMap, yellowMarkers);

... and this code creates all of the markers fine, but it does not add them into clusterer.

Can you give me some suggestions how I can fix this?

Tnx in adv!

UPDATE: maybe this can help - alert(yellowMarkers); shows alert window, with:

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4

2 回答 2

1

当我以前这样做时,我的代码如下所示:

var markerCluster = new MarkerClusterer(map, markers, {
            zoomOnClick: true,
            averageCenter: true
        });

是什么yellowMarkers?那不应该是 myMap.markers 吗?

于 2012-02-09T09:13:28.907 回答
0

我同意上面关于变量名称的一些评论,但我想在这里添加另一个选项。

您可以在开始添加任何标记之前初始化 markerclusterer:

var markerYellowCluster = new MarkerClusterer(myMap);

然后代替调用:

myMap.markers.push(marker_<?php echo $gauging["Gauging"]["id"]; ?>);

您可以简单地在 markerclusterer 对象本身上调用“addMarker”方法,它会同时将标记添加到地图以及标记聚类器:

markerYellowCluster.addMarker(marker_<?php echo $gauging["Gauging"]["id"]; ?>);
于 2012-02-09T21:38:34.870 回答