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 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).

Here are links to all of the posts in this series on how to create your own store locator map:

 

Create a spreadsheet of your store locations

Create and populate the MySQL table

Create a PHP file which will be used to connect to the database

Create a PHP file which will output the XML file results of a search

Create the HTML page which contains the store locator map

 

 And here are some hints and tips to help create and customize your store locator map:

Using your own custom markers for the locations in place of Google’s default markers

How to prevent the map from zooming in to close on a single location