我正在开发一个应用程序,它使用谷歌地图显示不同地点的列表,我一切正常,并使用 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/