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

11,183

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.

Share:
11,183
Admin
Author by

Admin

Updated on June 14, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

        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?