geocodezip 의견 덕분에 필자는 Mike Williams의 솔루션을 수정했습니다.
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);
}
}
참조 [이 설명] (http://econym.org.uk/gmap/range.htm) [마이크 윌리엄스 '구글 : 여기
는 fiddle example관련 코드의 일부이다 Maps API v2 튜토리얼] (http://econym.org.uk/gmap/). Google지도 Javascript API v2는 더 이상 사용되지 않지만 (사용 중지됨) 동일한 개념이 v3에 적용됩니다. – geocodezip