0

我在將標記添加到Google地圖標記Clusterer時遇到問題。螢火蟲返回錯誤:將標記添加到Google Maps clusterer時遇到問題

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

標記與JavaScript代碼結構和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); 

...這代碼創建的所有精細的標誌,但它並沒有將它們添加到人聚類。

你能給我一些建議,我可以解決這個問題嗎?

Tnx in adv!

更新:也許這可以幫助 - 警報(yellowMarkers);顯示警報窗口,以:

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] 
+0

可以喲你發佈php創建的輸出?你不必發佈標記的整個列表只有一個 – clem 2012-02-08 18:04:21

+0

與PHP我只添加標記屬性,並且它工作正常。問題是我無法將創建的標記組合到標記聚類器中。你認爲哪一部分的PHP代碼可以幫助你? – user198003 2012-02-08 18:09:01

回答

1

當我這樣做過,我的代碼是這樣的:

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

什麼是yellowMarkers?不應該是myMap.markers?

+0

變量yellowMarkers在我的情況是你的變量標記。就像我的變量myMap和你的地圖一樣。在我身邊肯定會有一些小錯誤...你能檢查我的問題的更新部分嗎? – user198003 2012-02-09 20:17:37

+1

如果你粘貼的代碼是你正在使用的代碼,那麼鄧肯的說法正確的是,yellowMarkers看起來並不像要使用的正確集合。你顯然已經在代碼中的某個地方填充了它,但是你發佈的代碼並不顯示在哪裏。它顯示你填充myMap.markers。所以試試var markerYellowCluster = new MarkerClusterer(myMap,myMap.markers); – DaveS 2012-02-09 21:17:43

+1

另外,在某個時候您引用MyMap.map,然後引用myMap.markers。 JavaScript區分大小寫。你只需將我的地圖傳遞給標記聚類器。你的意思是傳遞myMap.map嗎? – DaveS 2012-02-09 21:22:01

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"]; ?>); 
相關問題