How to zoom in smoothly on a marker in Google Maps?

后端 未结 6 1797
孤独总比滥情好
孤独总比滥情好 2020-12-22 22:28

I\'d like to be able to zoom in smoothly on a marker in Google Maps. If one just sets the zoom on double click, the map is suddenly on that zoom level, without any smooth tr

6条回答
  •  囚心锁ツ
    2020-12-22 23:09

    This one worked for me nicely:

    function animateMapZoomTo(map, targetZoom) {
        var currentZoom = arguments[2] || map.getZoom();
        if (currentZoom != targetZoom) {
            google.maps.event.addListenerOnce(map, 'zoom_changed', function (event) {
                animateMapZoomTo(map, targetZoom, currentZoom + (targetZoom > currentZoom ? 1 : -1));
            });
            setTimeout(function(){ map.setZoom(currentZoom) }, 80);
        }
    }
    

提交回复
热议问题