javascript - 谷歌地图 : map not extending bounds to view all markers

标签 javascript google-maps-api-3

我遇到了问题。我有我们经销商的一系列位置。它称为位置。每组中的第一项是纬度,每组中的最后一项是经度。我取回了一张 map ,上面的所有位置都正确,只是它放大了其中一个位置。它必须是有界限的东西,但我不确定是什么。有人可以帮忙吗?谢谢。

这是我的代码:

var map = new google.maps.Map(document.getElementById('map'), {
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });

var marker, i;

if (locations.length > 1) { 
    var bounds = new google.maps.LatLngBounds();
    for (i = 0; i < locations.length; i++) {  
        marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][0], locations[i][1]),
                    map: map
                });
    }

    bounds.extend(marker.getPosition());              

    map.fitBounds(bounds);

最佳答案

我认为您希望在 for 循环中使用 bounds.extend。在我看来,它只占据了一个标记的位置。

关于javascript - 谷歌地图 : map not extending bounds to view all markers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10841053/

相关文章:

javascript - 在固定大小的列中加载 html 正文内容

javascript - 如何在不刷新页面的情况下获取laravel数据?

javascript - 谷歌地图创建隐藏的 div 并在内部跨越值 BESbswy 并降低 Angular 性能

google-maps - 绕过Google Geocoding API IP速率限制

javascript - 触发输入文件点击不会弹出文件上传对话框

javascript - jqGrid - 在 IE 中产生 SCRIPT5007 错误,但在本地主机上工作

javascript - Marker Clusterer Plus 单击时删除簇

javascript - 是什么导致 "Uncaught RangeError: Maximum call stack size exceeded"错误? (Chrome,在其他浏览器中其他消息)

javascript - Google map 项目不适用于移动设备

Javascript::文本区域中的新行