clearOverlays()

2,542 views
Skip to first unread message

camainc

unread,
May 28, 2009, 6:01:53 PM5/28/09
to Google Maps JavaScript API v3
I'm trying to call "map.clearOverlays()" but I get an error
"map.clearOverlays is not a function."

Any ideas?

String

unread,
May 29, 2009, 2:44:40 AM5/29/09
to Google Maps JavaScript API v3
On May 28, 11:01 pm, camainc <cama...@gmail.com> wrote:

> I'm trying to call "map.clearOverlays()" but I get an error
> "map.clearOverlays is not a function."

I don't see a map.clearOverlays() in v3:
http://code.google.com/apis/maps/documentation/v3/reference.html

In my experience, you'll need to keep track of your overlays yourself
as you add them, then remove them manually. I would think it's part of
keeping this API "lightweight."

String

ch.ri...@bluewin.ch

unread,
May 29, 2009, 10:08:33 AM5/29/09
to Google Maps JavaScript API v3
Hi,

Is there any sample that shows how to "remove" markers?

John Coryat

unread,
May 29, 2009, 10:26:06 AM5/29/09
to google-map...@googlegroups.com
Use

object.set_map(null) ;

To remove them from the map.

timothyb

unread,
Jun 9, 2009, 4:20:27 AM6/9/09
to Google Maps JavaScript API v3
My 2 cents worth is that it would make sense to have a documented
equivalent to remove all the overlays.

I don't think I have any need to track the google.maps.Marker marker
objects I create. I simply maintain an object
count, some index related info and the lat, lng of all the markers I
have set down as the user is moving around the map.
When the user gets to a point where I deem the number of markers laid
down as 'excessive' e.g. due to labelling constraints
on the new markers, I'm simply re-indexing (going back to my base
index) and writing the new Marker objects in the current
viewport. It would be nice here to remove all the old Marker's I had
created. (For the moment, I can just write over the old ones
if the user happens to move back to where the viewport previously
was).

Tim Burgess

Esa

unread,
Jun 18, 2009, 6:55:34 PM6/18/09
to Google Maps JavaScript API v3
Every time you create a marker, push it into an array. Clearing all
the markers can be done by a simple loop.

for(var i=0; i<markers.length; i++){
markers[i].set_map(null);
}

It may be a good idea memorywise to null the marker objects. Also the
array can be reset for future use. So the full function might look
like:

function clearMarkers(){
for(var i=0; i<markers.length; i++){
markers[i].set_map(null);
markers[i] = null;
}
markers.length = 0;
}
Message has been deleted

Rudialex

unread,
Jun 30, 2009, 3:00:00 PM6/30/09
to Google Maps JavaScript API v3
I use array layers for each new "layerSet"

Its useful if needed to hide and then show again without adding again
same marker. So I use this way

item.set_visible(false);

And then just

item.set_visible(true);

and we dont need to check and refer to map tp show it. But if needed
to move marker to new map then - here better set_map.
Reply all
Reply to author
Forward
0 new messages