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

Related Posts:

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

  1. [...] View post: Creating your own store locator map: How to prevent the map from … [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">