Remove multiple circle

2,903 views
Skip to first unread message

en4ce

unread,
Feb 2, 2011, 3:38:58 PM2/2/11
to Google Maps JavaScript API v3
hi guys...

i want to remove multiple circles on my map but so far i have no
success with it :/

circle.setMap(null) works well with just one circle

this:

if(circle != null){
for (var i in circle) {
circle[i].setMap(null)
}
}

throughs an exception: Uncaught TypeError: Object #<an Object> has no
method 'setMap'

i looked up google now for quite some time... :/

the circles are created as this:

circle = new google.maps.Circle({map: map,radius: 30});
circle.bindTo('center', marker, 'position');

any suggestions? thx!

JKurtock

unread,
Feb 2, 2011, 3:49:54 PM2/2/11
to Google Maps JavaScript API v3
from the very tiny fragment you provide, it looks like you are
creating multiple circles, and each one is assigned to the variable
circle, one after the other. circle is not an array of circles, it is
just the last one. So circle.setMap(null) removes that last circle.
circle[i] doesn't work because circle is not an array. (circle is an
object of some sort, and when you try to access circle[i] it may be
pulling out a part of that object, which part does not have the method
setMap. Hence the error, maybe.)

You could try creating variable circle as an array, then in a loop
assign circle[i]= new google.maps.Circle(.....)

- Jeff

en4ce

unread,
Feb 2, 2011, 4:04:46 PM2/2/11
to Google Maps JavaScript API v3
J!

well, it realy pulled out objects so i thought its an array, obviously
it was not....

i created an array as you said... works now!

thank you
Reply all
Reply to author
Forward
0 new messages