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 transition.
Zooming in only one level further than the current level, Google Maps shows a nice smooth transition. So it must be possible to zoom in smoothly for more than one level, but how?
As luck would have it, I wanted to achieve the same effect recently, and found a solution, which I made a post about. Basically, just setting a timeout for each transition isn’t enough, because it could easily result in a ‘start-stop’ kind of zoom if Google’s zoom effect isn’t finished yet, or has long finished.
As Martin mentioned, there are some disadvantages to this, which I won’t reiterate. Whether you use this in the end is your choice, and depends largely on your users’ CPU power and/or browser. It is a nice effect though, and sure to impress some, when used wisely.
My solution was the following:
Basically what it comes down to is adjusting the zoom level by one, listening for the
zoom_changedevent, waiting 80ms before adjusting the zoom-level by one again, etc. What’s nice about this is that thezoom_changedevent seems to be called after the smooth transition provided by Google Maps, but before the actual images are loaded, so it doesn’t waste bandwidth too much.The 80ms in the timeout is also a magic number I came up with – you would be well-advised to do a more thorough test and see what works on different systems and browsers, and perhaps change the algorithm slightly based on your findings or for different systems.
It’s probably also not necessary to add and remove the listener every time, but you can make that small improvement yourself if you so wish.