views:

1089

answers:

1

I am developing a Google Maps application and I've run into this problem. I need to remove all markers which are out of bounds from the map.

Is there any simple way of doing this, besides keeping an array and looking at the latlng of each marker?

I cannot use MarkerManager because I have way too many points. I don't want to use clearOverlays() because it would close any open marker.

Any help would be appreciated.

+3  A: 

If you don't want to look at each marker individually then cluster them into some sets initially and calculate the bounds of the set.

You can then show or hide the sets depending on what is currently showing on the map (you can find the boundary of the map using GMap2.getBounds() ).

How many points are we talking about?

Update

A. About 65K.

I can see why you can't create 65K GMarkers when the page loads. That will take over 5 seconds.

I'd cluster them into groups of 200 ish and when the edge of the group gets within a 1/4 map width outside of the displayed edge then find, create markers and display the adjacent group. It it goes outside of 1/2 a map width of the outside edge then hide the group.

Other alternatives are to use a third party library such as

RichH
65k, but I will never show more than 300 at a time
Sklivvz
Thanks for the tip, the other problem is that downloading the info to generate 65k markers would take too long...
Sklivvz
Group them server side and load the group bounds in the initial page load. You can then download the points on the fly using AJAX as the groups get near to the displayed portion of the map.
RichH