2014-05-10 1 views
1

google maps v3 javascript API 사용 북극점 또는 남극점을 통해지도 패닝을 차단하는 방법을 찾을 수 없습니다. 예제로이 페이지에 포함 된지도 : https://developers.google.com/maps/documentation/embed/guide 은 동일한 동작을하며, 월드 뷰로 축소하고 북쪽으로 패닝하면 전체 회색 영역으로 표시됩니다.Google지도 API 차단 v3을 북극 위의 회색 영역 또는 남극 아래의 회색 영역에서 차단하는 방법은 무엇인가요?

공식 사이트에서 행해지 진 것을 예방하는 방법 http://maps.google.it?

+0

참조 [이 설명] (http://econym.org.uk/gmap/range.htm) [마이크 윌리엄스 '구글 : 여기

fiddle example

관련 코드의 일부이다 Maps API v2 튜토리얼] (http://econym.org.uk/gmap/). Google지도 Javascript API v2는 더 이상 사용되지 않지만 (사용 중지됨) 동일한 개념이 v3에 적용됩니다. – geocodezip

답변

15

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); 
    } 
} 
+0

왜 85가 궁금하신 분은 [latlongrid.gif] (http://www.csgnetwork.com/latlongrid.gif)를 참조하십시오. 포스터는 85도 내에서 뷰포트를 제한하려고했습니다. –

관련 문제