Google Maps API V3 infoWindow - 显示相同内容的所有infoWindows [英] Google Maps API V3 infoWindow - All infoWindows displaying same content
问题描述
在我的页面中,纬度,经度和信息窗口内容存在于一个名为obj的对象数组中。
所以如果我需要第一个属性的纬度对象,我可以调用obj [0] .latitude。每个对象的infoWindow内容都存储在obj [i] .text中。
我使用下面的循环来遍历lat&显示标记和infoWindows。
for(x = 1; x <= obj.length; x ++)
{
var latlng1 = new google.maps.LatLng(obj [x] .latitude,obj [x] .longitude);
var marker2 =新增google.maps.Marker({
位置:latlng1,
地图:地图,
图标:prevIcon
});
infowindow = new google.maps.InfoWindow();
info = obj [x] .text;
google.maps.event.addListener(marker2,'mouseover',function(){
infowindow.setContent(info);
infowindow.open(map,this);
});
}
$ c $
上面的代码有效,但所有的infoWindows都显示了最后一个obj [i] .text的内容。
如何将特定infoWindow(obj [x] .text)的infoWindow内容关联到该infoWindow实例?
有人可以指出一个解决方案,而不使用jQuery或任何其他外部库。
谢谢,
我设法实现了info变量的函数关闭。
以下Google网上论坛帖子解释了如何操作。
https://groups.google.com/group/google-maps-api-for-flash/browse_thread/thread/befeb9bf2d1ebcc9
感谢所有人:)
In my page, latitude, longitude and info window content are present in an array of objects named obj.
So if I need the latitude of property of the 1st object, I can call obj[0].latitude.
The infoWindow content for each object is stored in obj[i].text.
I'm using the below loop to loop through the lat & long values and display the markers and infoWindows.
for (x=1; x<=obj.length; x++)
{
var latlng1 = new google.maps.LatLng(obj[x].latitude, obj[x].longitude);
var marker2 = new google.maps.Marker({
position : latlng1,
map : map,
icon : prevIcon
});
infowindow = new google.maps.InfoWindow();
info = obj[x].text;
google.maps.event.addListener(marker2, 'mouseover', function() {
infowindow.setContent(info);
infowindow.open(map, this);
});
}
The above code works, but all the infoWindows are showing the content of the last obj[i].text.
How do I associate the infoWindow content of a particular infoWindow (obj[x].text) to that infoWindow instance only?
It would be better if someone can point out a solution without using jQuery or any other external libraries.
Thanks,
BGerrissen's comment above helped a lot.
I managed to achieve function closure on the info variable.
The following Google Groups post explains how to.
https://groups.google.com/group/google-maps-api-for-flash/browse_thread/thread/befeb9bf2d1ebcc9
Thanks everyone :)
这篇关于Google Maps API V3 infoWindow - 显示相同内容的所有infoWindows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!