How to change the radius of the circle around the marker in Google Map API
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?
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.
精彩评论