Google地图openInfoWindowHTML数组问题 [英] Google Maps openInfoWindowHTML array problem
本文介绍了Google地图openInfoWindowHTML数组问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var map = new GMap2(document.getElementById(map)) ;
map.addControl(新的GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(47.6062,-122.3321),8);
var wa_locations = new Array(new Array(Seattle,47.6062,-122.3321,### - ### - ####,### - ### - ####),
new Array(Bellevue,47.6104,-122.2007,### - ### - ####,### - ### - ####),
new Array(Tacoma,47.2529,-122.4443,### - ### - ####,### - ## # - ####),
new Array(Everett,47.9790,-122.2021,### - ### - ####,### - # ## - ####));
for(var i = 0; i< wa_locations.length; i ++)
{
var point = new GLatLng(wa_locations [i] [1],wa_locations [i] [2] );
map.addOverlay(new GMarker(point));
GEvent.addListener(point,click,function()
{
point.openInfoWindowHtml(< b> + wa_locations [i] [0] +< / b> ;< br /> Sales:+ wa_locations [i] [3] +< br />帮助台:+ wa_locations [i] [4] +);
});
解决方案
你的观点,而不是你的标记。此外,从您的评论看来,你有一个JavaScript关闭问题。您可以使用 bindInfoWindowHtml 来避免侦听器和关闭>。下面是使用标记和bindInfoWindowHtml进行调整的最后部分:
$ b
for(var i = 0; i< wa_locations.length; i ++)
{
var point = new GLatLng(wa_locations [i] [1],wa_locations [i] [2]);
var marker = new GMarker(point);
marker.bindInfoWindowHtml(< b> + wa_locations [i] [0] +< / b>< br /> Sales:+ wa_locations [i] [3] +< br /> Helpdesk:+ wa_locations [i] [4] +);
map.addOverlay(marker);
}
Could someone please help explain why I can't get this to work? I properly generates all the locations, however, it doesn't generate the info boxes. Why is this and can someone help me with it?
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(47.6062, -122.3321), 8);
var wa_locations = new Array(new Array("Seattle", "47.6062", "-122.3321", "###-###-####", "###-###-####"),
new Array("Bellevue", "47.6104", "-122.2007", "###-###-####", "###-###-####"),
new Array("Tacoma", "47.2529", "-122.4443", "###-###-####", "###-###-####"),
new Array("Everett", "47.9790", "-122.2021", "###-###-####", "###-###-####"));
for(var i = 0; i < wa_locations.length; i++)
{
var point = new GLatLng(wa_locations[i][1], wa_locations[i][2]);
map.addOverlay(new GMarker(point));
GEvent.addListener(point, "click", function()
{
point.openInfoWindowHtml("<b>" + wa_locations[i][0] + "</b><br/>Sales: " + wa_locations[i][3] + "<br/>Helpdesk: " + wa_locations[i][4] + "");
});
}
解决方案
You are adding a listener to your point instead of to your marker. Further, from your comment it appears you have a JavaScript closure issue. You can avoid the listener and the closure by using bindInfoWindowHtml. Here's the last part tweaked to use the marker and bindInfoWindowHtml:
for(var i = 0; i < wa_locations.length; i++)
{
var point = new GLatLng(wa_locations[i][1], wa_locations[i][2]);
var marker = new GMarker(point);
marker.bindInfoWindowHtml("<b>" + wa_locations[i][0] + "</b><br/>Sales: " + wa_locations[i][3] + "<br/>Helpdesk: " + wa_locations[i][4] + "");
map.addOverlay(marker);
}
这篇关于Google地图openInfoWindowHTML数组问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文