2011-09-26 8 views
2

콤보 메뉴의 값을 변경하여 원 반경을 변경하려고합니다. 그래서 나는 onchange 함수를 다음과 같이 썼다.Google Map API에서 마커 주변의 원 반경을 변경하는 방법

function changeRadius(){ 
     var selectedRadius = (document.getElementById("circle_radius").value)*1000; 

     var circle = new google.maps.Circle({ 
       map: map, 
       radius: selectedRadius // radius unit is meter. 
      }); 

     var marker2 = new google.maps.Marker({ 
       map: map, 
       position: new google.maps.LatLng(40,-90), 
       draggable: true, 
       title: 'Drag me!' 
      }); 

     circle1.bindTo('center', marker2, 'position'); 

    } 

하지만 작동하지 않습니다. 어떤 생각?

+1

google maps api documentation이 원에 대한 bindTo() 함수를 나타내지 않고 자체 함수입니까? – slawekwin

+0

이 질문은 https://stackoverflow.com/questions/15095118/interactive-circle-in-google-map-which-changes-on-changing-radius의 중복이며 원하는 답변은 https :// /stackoverflow.com/a/15095490/1290746 – kris

답변

4

당신은 이런 식으로 뭔가를해야 할 것이다 : 당신이 circle_radius 콤보 값 변경 이벤트에 대한 리스너로서 기능을 설정합니다이 기능

google.maps.event.addDomListener(
    document.getElementById('circle_radius'), 'change', function() { 
     circle.setRadius(document.getElementById('circle_radius').value) 
    }); 

합니다. 이 함수는 원의 반경을 콤보 값으로 업데이트합니다.

관련 문제