UPDATE - The following answer doesn't look to work anymore, I suppose it's because google maps API has been upgrade. I leave the code here for reference.
Thanks to geocodezip comments i modified Mike Williams' solution for my case.
Here is the fiddle example
Relevant code part:
google.maps.event.addListener(map, 'center_changed', function() {
checkBounds(map);
});
// If the map position is out of range, move it back
function checkBounds(map) {
var latNorth = map.getBounds().getNorthEast().lat();
var latSouth = map.getBounds().getSouthWest().lat();
var newLat;
if(latNorth<85 && latSouth>-85) /* in both side -> it's ok */
return;
else {
if(latNorth>85 && latSouth<-85) /* out both side -> it's ok */
return;
else {
if(latNorth>85)
newLat = map.getCenter().lat() - (latNorth-85); /* too north, centering */
if(latSouth<-85)
newLat = map.getCenter().lat() - (latSouth+85); /* too south, centering */
}
}
if(newLat) {
var newCenter= new google.maps.LatLng( newLat ,map.getCenter().lng() );
map.setCenter(newCenter);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…