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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7551914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:31:10  来源:igfitidea点击:

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

javascriptapigoogle-maps

提问by karthikeyank

I am trying to change the circle radius by changing the value of combo-menu. So I wrote the a function for onchange as below.

我试图通过更改组合菜单的值来更改圆半径。所以我为 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'); 

   }

But It doesn't work. Any idea?

但它不起作用。任何的想法?

回答by Victor Franch

You'll have to do something like this:

你必须做这样的事情:

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

with this function you'll set up a function as listener for the circle_radius combo value change event. The function will update the radius of your circle with the value of the combo.

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