Restricting the bounds of the map

HTML

<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=&callback=initMap">
</script>

CSS

/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
#map {
  height: 100%;
}

/* Optional: Makes the sample page fill the window. */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

JavaScript

var map;
var CALIFORNIA_BOUNDS = {
  north: 42.009517,
  south: 32.528832,
  west: -124.482003,
  east: -114.131211
};
var CALIFORNIA = {
  lat: 36.778261,
  lng: -119.417932
};

function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: CALIFORNIA,
    restriction: {
      latLngBounds: CALIFORNIA_BOUNDS,
      strictBounds: false,
    },
    zoom: 7,
  });
}