Search code examples
phpjavascriptgoogle-mapsgoogle-maps-api-3markerclusterer

Having problems adding markers into Google Maps clusterer


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]

Solution

  • When I've done this before, my code looked like this:

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

    What is yellowMarkers? Shouldn't that be myMap.markers?