2011-09-26 63 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

谷歌地圖API文檔沒有說明任何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

你必須做這樣的事情:

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

使用此功能,您將設置一個函數作爲偵聽器circle_radius組合價值變動事件。該函數將用組合值更新圓的半徑。

相關問題