My code :
if(!bounds.isEmpty()) {
map.fitBounds(bounds);
if (map.getZoom() > 11) {
map.setZoom(11);
}
}
but I see that map.setZoom(11);
could be called before .fitBounds
end. So the result is not what I aspect for.
Is there a way to manage a callback when .fitBound
finish?
Try this:
if(!bounds.isEmpty()) {
map.fitBounds(bounds);
google.maps.event.addListenerOnce(map, 'idle', function() {
if (map.getZoom() > 11) {
map.setZoom(11);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With