2012-03-30 4 views
0

저는 stackoveflow에 처음 입하합니다. Google api v3를 사용하여 사각형을 그릴 수있는 방법을 알려줄 수 있습니다. Google에서 몇 가지 예제를 살펴 보았습니다. 아래 코드가 있습니다. 초기에 전화했을 때Google Map API를 사용하여 Google Map에 사각형을 그리는 방법

function initialize() { 

    var coachella = new google.maps.LatLng(33.6803003, -116.173894); 
    var rectangle; 

    var myOptions = { 
    zoom: 11, 
    center: coachella, 
    mapTypeId: google.maps.MapTypeId.TERRAIN 
    }; 

    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     myOptions); 

    rectangle = new google.maps.Rectangle(); 

    google.maps.event.addListener(map, 'zoom_changed', function() { 

    // Get the current bounds, which reflect the bounds before the zoom. 
    var rectOptions = { 
     strokeColor: "#FF0000", 
     strokeOpacity: 0.8, 
     strokeWeight: 2, 
     fillColor: "#FF0000", 
     fillOpacity: 0.35, 
     map: map, 
     bounds: map.getBounds() 
    }; 
    rectangle.setOptions(rectOptions); 
    }); 
} 

는하지만, 그것은 줌 이벤트 (줌 chanages), 난 밖으로 이벤트와 간단한 원하는에 기능, 즉시 (안 원하는 경계를 반환 할 수 있습니다) 나에게

답변

2

map.getBounds을 (도와주세요 지도를 인스턴스화 한 후).

당신은

google.maps.event.addListenerOnce(map, 'tilesloaded', function() { 
    /*your code*/ 
    }); 
대신 tilesloaded 사용할 수 있습니다
관련 문제