I'm new in javascript and I try to update the size of a circle in a google map when the value of the radius is updated but it doesn't work.
I tried to return the value of cityCircle when I update the radius but it returns "undefined".
setTimeout(function() {
google.maps.event.trigger(map, 'resize');
if (num_places > 0) {
var radiusmap = s.radius;
var cityCircle;
function addCircle() {
if (cityCircle) {
cityCircle.setMap(null);
} else {
cityCircle = new google.maps.Circle({
radius: radiusmap * 1000,
fillColor: '#bce3e4',
fillOpacity: 0.2,
strokeColor: '#7cc4c5',
strokeOpacity: 1,
strokeWeight: 1
});
cityCircle.bindTo('center', centerMarker, 'position');
cityCircle.bindTo('map', centerMarker, 'map');
}
}
if (radiusmap == 100) {
addCircle();
map.setCenter(latlng);
map.setZoom(8);
}
if (radiusmap == 50) {
console.log(cityCircle);
addCircle();
map.setZoom(9);
}
if (radiusmap == 20) {
addCircle();
map.setZoom(10);
}
if (radiusmap == 5) {
addCircle();
map.setZoom(12);
}
if (radiusmap == 0) {
map.setZoom(2);
}
} else {
map.setZoom(s.zoom);
map.setCenter(latlng);
}
}
Any help would be really appreciated :)