Google Maps Infowindow自动更新 [英] Google Maps Infowindow Auto Updating
问题描述
我有一个应用程序,需要 infowindow
气泡中的数据自动更新。我检查了一下,我看到了移动标记,更新标记颜色等的方法,但没有直接更新infowindow内容。我从内容自动更新的隐藏DOM元素中提取必要的值(例如 building [i] [7]
),我需要infowindow的内容自动更新。
下面是我用来绘制 infowindow
个泡泡的代码。
infowindow = new google.maps.InfoWindow();
for(i = 0; i< buildings.length; i ++){
marker = new google.maps.Marker({
position:new google.maps.LatLng(buildings [i] [4],建筑物[i] [5]),
地图:地图,
阴影,
图标:greenIcon,
标题:buildings [i] [0] +\ n+ buildings [i] [1],
zIndex:buildings [i] [6]
});
google.maps.event.addListener(marker,'click',(function(marker,i){
return function(){
infowindow.setContent(
'< h2>'+ buildings [i] [0] +'< / p>'+
'< p>'+ '+
'< p>'+ buildings [i] [7] +'< / p>'
); infowindow.open(map,marker);
}
})(marker,i));
非常感谢您的任何帮助!
当JavaScript中的内置方式在 DIV
的内容发生变化时得到通知,但我相信<一个href =http://api.jquery.com/bind/ =nofollow> jQuery.bind()函数或更新的(jQuery v1.7) jQuery.on()函数提供了一种实现你想实现的方法。
I have an app in which I need the data in the infowindow
bubbles to update automatically. I've checked around and I see methods for moving markers, updating marker colors, and the like, but nothing with directly updating infowindow content. I am pulling the value necessary (e.g. building[i][7]
) from a hidden DOM element whose content automatically updates, and I need the infowindow's content to automatically update alongside it.
Here is the code I am using to draw the infowindow
bubbles.
infowindow=new google.maps.InfoWindow();
for (i=0;i<buildings.length;i++){
marker=new google.maps.Marker({
position:new google.maps.LatLng(buildings[i][4],buildings[i][5]),
map:map,
shadow:shadow,
icon:greenIcon,
title:buildings[i][0]+" \n"+buildings[i][1],
zIndex:buildings[i][6]
});
}
google.maps.event.addListener(marker,'click',(function(marker,i){
return function(){
infowindow.setContent(
'<h2>'+buildings[i][0]+'</h2>'+
'<p>'+buildings[i][2]+'</p>'+
'<p>'+buildings[i][7]+'</p>'
);infowindow.open(map,marker);
}
})(marker,i));
Any help is greatly appreciated!
There isn't a built-in way in JavaScript to be notified when the content of a DIV
changes, but I believe the jQuery.bind() function or the newer (jQuery v1.7) jQuery.on() function provide a way to implement what you are trying to achieve.
这篇关于Google Maps Infowindow自动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!