繁体   English   中英

如何在Google Map API中更改标记周围的圆的半径

[英]How to change the radius of the circle around the marker in Google Map API

我正在尝试通过更改组合菜单的值来更改圆半径。 所以我写了如下的onchange函数。

    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'); 

   }

但这行不通。 任何想法?

您将必须执行以下操作:

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

使用此函数,您可以将一个函数设置为circle_radius组合值更改事件的侦听器。 该功能将使用组合的值更新圆的半径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM