Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 多个标记的信息窗口映射错误_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

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();