javascript - 谷歌地图 : How to zoom out to all locations on map

标签 javascript jquery google-maps

我正在开发一个应用程序,它使用谷歌地图显示不同地点的列表,我一切正常,并使用 currentLocation 和最近的位置,它会缩放以显示这一点,但我尝试更改此设置以使其它会缩小以显示所有建筑物,而不仅仅是最近的建筑物

编辑:这是工作代码

// Sets the bounds of the map to include at lease one visable marker
function setBounds(){
if ( markerCluster.getMarkers().length > 0 && homeMarker != null){
    map.setZoom(17);
    var visableMarkers = markerCluster.getMarkers();
    // want to set the starting position at the homeMarker

    //Make an array of the LatLng's of the markers you want to show
    var LatLngList = new Array ();
    LatLngList.push(homeMarker.position);
    $.each(visableMarkers, function() {
        LatLngList.push(this.position);    
    });

    //  Create a new viewpoint bound
    var bounds = new google.maps.LatLngBounds ();
    //  Go through each...
    for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
        //  And increase the bounds to take this point
        bounds.extend (LatLngList[i]);
    }
    //  Fit these bounds to the map
    map.fitBounds (bounds); 
}
}

最佳答案

您的数组LatLngList的代码不正确,我认为应该说

var LatLngList = new Array (new google.maps.LatLng (52.537,-2.061), new google.maps.LatLng (52.564,-2.017));

关于javascript - 谷歌地图 : How to zoom out to all locations on map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10284451/

相关文章:

c# - 单击按钮读取动态表值

android - 如何在 jetpack compose 中检测拖动手势谷歌地图?

android - 两个地点之间的距离(不显示 map )

android - 如果没有 Google Play 服务,googleMapsApp(项目名称)将无法运行。您的设备不支持哪些

javascript - 如何在用户单击菜单时保持焦点?

javascript - 从列中删除 jqGrid 编辑选项

javascript - 如何解码 JSON 对象并对其进行迭代?

javascript - 当样式属性在宽度或高度之后排序时,jQuery 元素创建会删除宽度和高度

javascript - 在字符串中保持匹配正则表达式,直到没有匹配项

javascript - 为什么 CORS 允许向任何服务器发送数据?