Skip to content

Instantly share code, notes, and snippets.

@mturnwall
Created January 17, 2013 20:19
Show Gist options
  • Save mturnwall/4559361 to your computer and use it in GitHub Desktop.
Save mturnwall/4559361 to your computer and use it in GitHub Desktop.
Make sure google maps isn't zoomed too far in when updating locations. You might want this because when one location is returned the map will be zoomed in as far as it can go. So you might want to make sure the zoom level never goes past a certain point.
/*
call this snippet after you call map.fitBounds();
replace "map" with the instance to your map
change the zoomThreshold to the zoom level you want the map never to zoom
past when loading locations
*/
google.maps.event.addListenerOnce(map, 'zoom_changed', function() {
var oldZoom = map.getZoom(),
zoomThreshold = 16;
if (oldZoom > zoomThreshold) {
map.setZoom(zoomThreshold);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment