javascript - map.fitBounds 之后有回调吗?

标签 javascript google-maps google-maps-api-3

我的代码:

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/

相关文章:

javascript - 根据另一个数组从 JavaScript 数组中删除重复项?

json - 从 Google map 地点搜索中获取地址组件

html - jquery 移动谷歌地图间歇性显示

javascript - 如何显示编码折线数组?

javascript - jquery:如何监听一个容器 div 的图像加载事件?

javascript - 在 JavaScript 中使用 Twitter Bootstrap 字形

javascript - 初始化谷歌地图而不可见= bug

google-maps - 仅在 Google map 中显示特定城市的标签

javascript - 如何修复 React-Native 中的 Error 'You Likely forgot to export your component from the file..etc' 错误?

php - 在 php 中将谷歌地图转换为 pdf