Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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

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,我尝试在一个页面上显示多个自定义谷歌地图,但当其中一个显示时,另一个出现了错误,如下图所示: 我不觉得它来自我的代码,因为这两个容器都适合正确的大小,并且谷歌徽标和使用条款都正确显示。但是,贴图分幅不会显示在第二个贴图中,而是应用灰色背景 有什么想法/建议吗 编辑:第一张地图似乎总是显示出来,而其他地图总是被窃听。给google.maps.event.triggersecondmap“resize”;a去看看会发生什么。我终于找到了如何解决我的问题,这是@Andy的解决方案和我的解决方案的混合。

我尝试在一个页面上显示多个自定义谷歌地图,但当其中一个显示时,另一个出现了错误,如下图所示:

我不觉得它来自我的代码,因为这两个容器都适合正确的大小,并且谷歌徽标和使用条款都正确显示。但是,贴图分幅不会显示在第二个贴图中,而是应用灰色背景

有什么想法/建议吗


编辑:第一张地图似乎总是显示出来,而其他地图总是被窃听。

给google.maps.event.triggersecondmap“resize”;a去看看会发生什么。

我终于找到了如何解决我的问题,这是@Andy的解决方案和我的解决方案的混合。确实必须触发调整大小事件,但是缩放级别和地图中心未正确显示,如下所示:

要更新缩放级别和中心,我使用此自制方法,根据地图标记更新地图的边界:

var updateBounds = function ( map, markers ) {
    var bounds = new google.maps.LatLngBounds();

    for ( var i = 0, len = markers.length ; i < len ; i++ ) {
        bounds.extend ( markers[i].marker.position );
    }

    // extend bounds using two invisible markers so the markers don't get too close to the map borders
    var
        extendPoint1 = new google.maps.LatLng ( bounds.getNorthEast().lat() + 0.001, bounds.getNorthEast().lng() + 0.001 ),
        extendPoint2 = new google.maps.LatLng ( bounds.getNorthEast().lat() - 0.001, bounds.getNorthEast().lng() - 0.001 );

    bounds.extend ( extendPoint1 );
    bounds.extend ( extendPoint2 );

    map.fitBounds ( bounds );
};

你能分享一些代码吗。在每个浏览器上都是这样的吗?第二个贴图的外观与贴图在需要其名为.Mmh的调整大小功能时的外观相同。我希望这是一只已知的虫子。这个例子来自Chrome,也发生在Firefox上。事实上,这并不是每次都会发生,有时第二个被窃听,但不是第一个。。。我使用json-p加载地图数据,所以我想应该是先到先得。显示代码是相当棘手的,因为有许多文件和许多方法。。。我会想办法的。给google.maps.event.triggersecondmap加上“resize”;a去看看会发生什么。我把它作为一个答案添加进来。我在你自己的答案中找到了一些糖分:这里还有一个:但尽管它似乎符合我的问题,但它并不能解决它。我还有这个问题。