This solution is based on Marcelo's very good answer, however his solution will completely disable any further dragging (including valid dragging of the visible area of the map), once the map goes beyond the world's maximum or minimum latitude. Here's a clarified version, that will pull the map back into view if the user has exceeded the maximum or minimum latitude by dragging. It will still allow the user to drag for all visible areas.
Also, this solution sets a minimum zoom level for the map, which can be used to to ensure that attempted zooming doesn't cause the map to display grey areas.
(see also How do I limit panning in Google maps API V3?)
var lastValidCenter;
var minZoomLevel = 2;
setOutOfBoundsListener();
function setOutOfBoundsListener() {
google.maps.event.addListener(map, 'dragend', function () {
checkLatitude(map);
});
google.maps.event.addListener(map, 'idle', function () {
checkLatitude(map);
});
google.maps.event.addListener(map, 'zoom_changed', function () {
checkLatitude(map);
});
};
function checkLatitude(map) {
if (this.minZoomLevel) {
if (map.getZoom() < minZoomLevel) {
map.setZoom(parseInt(minZoomLevel));
}
}
var bounds = map.getBounds();
var sLat = map.getBounds().getSouthWest().lat();
var nLat = map.getBounds().getNorthEast().lat();
if (sLat < -85 || nLat > 85) {
//the map has gone beyone the world's max or min latitude - gray areas are visible
//return to a valid position
if (this.lastValidCenter) {
map.setCenter(this.lastValidCenter);
}
}
else {
this.lastValidCenter = map.getCenter();
}
}
(I didn't use the 'center_changed' listener. The center_changed event fires continuously while the map is being panned, which potentially can prevent the user from ever panning to a grey area, instead of 'snapping back'. This can cause stackoverflow errors in Chrome though, because of the number of times the event will be triggered)