Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing a Google maps Circle/shape

I am creating a Circle using the google.maps.Circle() method. This all works fine and dandy, but how can I remove said circle?

My code:

var populationOptionsAgain = {   strokeColor: "#c4c4c4",   strokeOpacity: 0.35,   strokeWeight: 0,   fillColor: "#ffffff",   fillOpacity: 0.35,   map: map,   center: results[0].geometry.location,   radius: 40000 }; cityCircle = new google.maps.Circle(populationOptionsAgain); 
like image 211
Barrie Reader Avatar asked May 19 '11 12:05

Barrie Reader


People also ask

How do I drop a circle in Google Maps?

We found two handy tools that you can use to draw a radius on your map. One is CalcMaps, and the other one is Maps.ie. If you're using CalcMaps, click on Draw a circle and add the circle on the map area you're interested in. Use can then use the drop-down menu to select the radius type you want to use.


2 Answers

You need to call the setMap method on the Circle object to null:

cityCircle.setMap(null); 
like image 178
RedBlueThing Avatar answered Sep 28 '22 11:09

RedBlueThing


To remove a circle from the map, call the setMap() method passing null as the argument.

circle.setMap(null); 

Note that the above method does not delete the circle. It simply removes the circle from the map. If instead you wish to delete the circle, you should remove it from the map, and then set the circle itself to null.

https://developers.google.com/maps/documentation/javascript/shapes#circle_remove

like image 20
fmalina Avatar answered Sep 28 '22 12:09

fmalina