[英]JS Function undefined when it is clearly a prototype of the object I am using
我將GoogleMaps JS API V3與ClusterMarker一起使用。 到目前為止,到目前為止,我已經有了一個包含自定義集群的工作圖。
我決定需要一種方法來打開infoWindow,其中包含單擊的群集的一些信息,包括一些錨定鏈接。
我在SO和Google上進行了一些搜索,並從StackOverflow答案中得出了類似的建議。
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(markerCluster, 'clusterclick', function (clickedCluster) {
console.log(clickedCluster);
var center = clickedCluster.getCenter();
var latLng = new google.maps.LatLng(center);
// infowindow.setContent("Info Window");
// infowindow.setPosition(latLng);
// infowindow.open(map);
});
在console.log(clickedCluster)
我得到了一個Cluster對象,該對象具有6種方法和大量的屬性。 這些功能之一是getCenter()
,它返回“已單擊的群集圖標的中心”。
當我取消注釋此行時: var center = clickedCluster.getCenter();
我收到一條錯誤消息,說getCenter()不是函數。
有人可以幫我弄清楚我在這里做錯了什么嗎?
提前致謝
因此,解決該問題的方法是將clickedCluster
作為數組返回。 下面的作品很棒。
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(markerCluster, 'clusterclick', function (clickedCluster) {
var center = clickedCluster[0].getCenter();
var latLng = new google.maps.LatLng(center.lat(),center.lng());
infoWindow.setContent(getDailyDeals(center.lat(),center.lng()));
infoWindow.setPosition(latLng);
infoWindow.open(map);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.