[GIS] How to restrict zoom levels in the Google Maps API

google maps

Is it possible, in the Google Maps API v3, to restrict the zoom to specific levels (eg 16 and 7)?

In my case I wish to show city points at a global scale, then show suburb polygons when zoomed in – but I only want those 2 levels of zoom rather than the full 20 levels.

Thanks

Best Answer

Yes, but not directly. If you needed a range, you could use map.setOptions() and set the min/maxZoom. As you aren't looking for a range, I suggest listening for zoom events on the map, and restricting the zoom levels in the event handlers. I've done it with other APIs before, and its worked fine. There's an example on StackOverflow about doing something similar: Limit Viewable Area in GMaps v3 Oh, and you'll probably want to disable the zoom control to minimize/avoid user confusion.

Related Question