title: How to prevent panning outside world edges on google maps?
body: <p>I start by saying I have looked at plenty of SO answers, and <a href="https://stackoverflow.com/questions/23580831/how-to-block-google-maps-api-v3-panning-in-the-gray-zone-over-north-pole-or-unde">this one</a> is what gets closer.</p>
  
  <p>So basically I did:</p>
  
  <pre><code>    var defaultLatLong = {
          lat: 45.4655171, 
          lng: 12.7700794
      };
  
      var map = new google.maps.Map(document.getElementById('map'), {
        center: defaultLatLong,
        zoom: 3,
        minZoom: 3,
        restriction: {
          latLngBounds: {
            east: 180,
            north: 85,
            south: -85,
            west: -180
          },
          strictBounds: true
        }, ...
  </code></pre>
  
  <p>But that prevents top/bottom panning while it is still panning left/right.</p>
  
  <p>Any idea why?</p>
  
  <p><strong>UDPATE</strong></p>
  
  <p>I tried the following:</p>
  
  <pre><code>    var allowedBounds = new google.maps.LatLngBounds(
           new google.maps.LatLng(85, 180), 
           new google.maps.LatLng(-85, -180)
      );
      var lastValidCenter = map.getCenter();
  
      google.maps.event.addListener(map, 'center_changed', function() {
          if (allowedBounds.contains(map.getCenter())) {
            // still within valid bounds, so save the last valid position
            lastValidCenter = map.getCenter();
            return; 
          }
          // not valid anymore =&gt; return to last valid position
          map.panTo(lastValidCenter);
      });
  </code></pre>
  
  <p>But while it stops from panning horizontally, I cannot pan to the poles so top/bottom</p>