Javascript 多个标记的信息窗口映射错误
我有这个工作地图,然后我尝试集成多个标记与信息窗口遵循一步一步本教程,所以现在我得到了这个新版本的地图,但它不工作 下面是我认为添加的代码是如何工作的 这是两个信息窗口的顺序文本Javascript 多个标记的信息窗口映射错误,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我有这个工作地图,然后我尝试集成多个标记与信息窗口遵循一步一步本教程,所以现在我得到了这个新版本的地图,但它不工作 下面是我认为添加的代码是如何工作的 这是两个信息窗口的顺序文本 var infoWindowContent = [ ['<div class="info_content">' + '<h3>Ventura</h3>' + '<p>Ventura P</p>' + '</div>
var infoWindowContent = [
['<div class="info_content">' +
'<h3>Ventura</h3>' +
'<p>Ventura P</p>' +
'</div>'],
['<div class="info_content">' +
'<h3>Selvatica</h3>' +
'<p>Selvatica p</p>' +
'</div>']
];
您对代码没有什么问题: 弗斯特 控制台错误
未定义google
,原因如下:
var bounds = new google.maps.LatLngBounds();
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
在加载google js之前的文件顶部。将其移动到jQuery(文档)中。就绪(函数($){:
第二
为什么?它们已经放在地图上了
,您只需将它们附加到信息窗口
:
//marker = new google.maps.Marker({
// position: position,
// map: map,
// title: markers[i][0]
//});
var marker = markers[i];
在上面的代码中,是问题的根源(信息窗口未显示):您正在创建新的标记对象,而不是使用标记数组中的现有对象
第三
控制台错误:递归太多
原因:
var bounds = new google.maps.LatLngBounds();
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
这个问题很可能是边界
此时未定义。不确定原因,但太多递归
通常是由此引起的。我已经对此进行了注释,因此您必须了解如何在fitBounds
中传递有效值
第四
您在此处遇到sintax错误:
var infoWindow = new google.maps.InfoWindow(), marker, i;
你可能是说:
var infoWindow = new google.maps.InfoWindow();
工作小提琴:你说的“它不工作”是什么意思?我在小提琴上看到一个javascript错误未捕获的引用错误:google没有定义。你的代码中没有infoWindowContent
。仅供参考-你的markers数组已经是google.maps.Marker
对象。找到它,只是不够长。。。
var infoWindow = new google.maps.InfoWindow(), marker, i;
var infoWindow = new google.maps.InfoWindow();