谷歌地图:如何缩小到地图上的所有位置

Google Maps: How to zoom out to all locations on map

本文关键字:地图 位置 何缩小 缩小 谷歌地图      更新时间:2023-09-26

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

编辑:这是工作代码

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