Ask Your Question
0

Is it possible to adjust the zoom level after using the fitBounds method in Google Maps API v3?

asked 2022-05-14 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-10 02:00:00 +0000

devzero gravatar image

Yes, it is possible to adjust the zoom level after using the fitBounds method in Google Maps API v3. You can use the setZoom method to set the new zoom level. For example:

// Create a new map
var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: {lat: 37.7749, lng: -122.4194}
});

// Create a LatLngBounds object
var bounds = new google.maps.LatLngBounds();

// Extend the bounds to include multiple locations
bounds.extend(new google.maps.LatLng(37.7749, -122.4194));
bounds.extend(new google.maps.LatLng(37.7749, -122.4195));
bounds.extend(new google.maps.LatLng(37.7748, -122.4194));
bounds.extend(new google.maps.LatLng(37.7748, -122.4195));

// Fit the map to the bounds
map.fitBounds(bounds);

// Set a new zoom level
map.setZoom(12);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-14 11:00:00 +0000

Seen: 8 times

Last updated: Aug 10 '21