Tag Archives: zoom

Creating your own store locator map: How to prevent the map from zooming in too close on a single marker

When I was developing a custom store locator for a website I was working on, one of the issues I ran into was the map zooming in way too close when only a single marker or location was found within the radius I had set.

The way I found to prevent the map from zooming in to far is by adding this line of code to the <head> section of the page:

var zoomOverride = map.getZoom();
        if(zoomOverride > 15) {
        zoomOverride = 15;
        }
      map.setZoom(zoomOverride);
The code above should be placed directly after this line:
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
Feel free to change the zoom level to whatever level you don’t want the map to zoom past. (Hint: the lower the number, the farther out the map is zoomed, and the higher the number, the closer in the map is zoomed).