How to smoothly zoom in on an object in Google Maps V3

When wanting to zoom in on a specific object in Google Maps (e.g. on double- click), the API provides no good functionality to zoom in onto the object smoothly. Here is a short snippet on how I achieved the effect. As always, any comments, suggestions and alterations are welcome!

// example marker:  
marker = new google.maps.Marker({
                    map: map, 
                    position: new google.maps.LatLng(-20.3,30.3)

// add the double-click event listener  
google.maps.event.addListener(marker, 'dblclick', function(event){
    map = marker.getMap();

    map.setCenter(overlay.getPosition()); // set map center to marker position
    smoothZoom(map, 12, map.getZoom()); // call smoothZoom, parameters map, final zoomLevel, and starting zoom level

// the smooth zoom function
function smoothZoom (map, max, cnt) {
    if (cnt >= max) {
    else {
        z = google.maps.event.addListener(map, 'zoom_changed', function(event){
            self.smoothZoom(map, max, cnt + 1);
        setTimeout(function(){map.setZoom(cnt)}, 80);
Fork Herman Schaaf's IronZebra blog on GitHub

Herman Schaaf is a full-stack developer in Tokyo, Japan. He often works on language-related open source projects, and has recently developed a keen interest in Go. He's a friendly guy who sometimes talks about himself in third person. You can reach him at @ironzeb or via email. Or, read some more posts.