最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change the radius of the circle around the marker in Google Map API - Stack Overflow

programmeradmin7浏览0评论

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

    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?

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

    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?

Share Improve this question edited Oct 10, 2014 at 20:01 gstackoverflow 37k138 gold badges417 silver badges782 bronze badges asked Sep 26, 2011 at 7:37 karthikeyankkarthikeyank 311 gold badge1 silver badge2 bronze badges 2
  • 1 google maps api documentation doesn't state any bindTo() function for circle, is it your own function, what does it do? – slawekwin Commented Sep 26, 2011 at 7:57
  • This question is a duplicate of stackoverflow./questions/15095118/… , and the answer you want is here : stackoverflow./a/15095490/1290746 – kris Commented Jul 5, 2017 at 5:10
Add a ment  | 

1 Answer 1

Reset to default 5

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 bo value change event. The function will update the radius of your circle with the value of the bo.

发布评论

评论列表(0)

  1. 暂无评论