Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This script gets the initial bounds (<code>allowedBounds</code>) and limit the bounds on <code>drag</code> and <code>zoom_changed</code>. Also the zoom is limited on &lt; 7.</p> <pre><code>var allowedBounds = false; google.maps.event.addListener(map, 'idle', function() { if (!allowedBounds) { allowedBounds = map.getBounds(); } }); google.maps.event.addListener(map, 'drag', checkBounds); google.maps.event.addListener(map, 'zoom_changed', checkBounds); function checkBounds() { if (map.getZoom() &lt; 7) map.setZoom(7); if (allowedBounds) { var allowed_ne_lng = allowedBounds.getNorthEast().lng(); var allowed_ne_lat = allowedBounds.getNorthEast().lat(); var allowed_sw_lng = allowedBounds.getSouthWest().lng(); var allowed_sw_lat = allowedBounds.getSouthWest().lat(); var currentBounds = map.getBounds(); var current_ne_lng = currentBounds.getNorthEast().lng(); var current_ne_lat = currentBounds.getNorthEast().lat(); var current_sw_lng = currentBounds.getSouthWest().lng(); var current_sw_lat = currentBounds.getSouthWest().lat(); var currentCenter = map.getCenter(); var centerX = currentCenter.lng(); var centerY = currentCenter.lat(); if (current_ne_lng &gt; allowed_ne_lng) centerX = centerX-(current_ne_lng-allowed_ne_lng); if (current_ne_lat &gt; allowed_ne_lat) centerY = centerY-(current_ne_lat-allowed_ne_lat); if (current_sw_lng &lt; allowed_sw_lng) centerX = centerX+(allowed_sw_lng-current_sw_lng); if (current_sw_lat &lt; allowed_sw_lat) centerY = centerY+(allowed_sw_lat-current_sw_lat); map.setCenter(new google.maps.LatLng(centerY,centerX)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload