我的代码:
if(!bounds.isEmpty()) {
map.fitBounds(bounds);
if (map.getZoom() > 11) {
map.setZoom(11);
}
}
但我看到 map.setZoom(11);
可以在 .fitBounds
结束之前调用。所以结果不是我所期待的。
.fitBound
完成时有没有办法管理回调?
最佳答案
试试这个:
if(!bounds.isEmpty()) {
map.fitBounds(bounds);
google.maps.event.addListenerOnce(map, 'idle', function() {
if (map.getZoom() > 11) {
map.setZoom(11);
}
});
}
关于javascript - map.fitBounds 之后有回调吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10835496/