Most efficient way to get visible markers on the map?

I have a map with tens / hundreds of thousands of markers on it, currently stored in an array ( docs for Marker Class ), I need to find markers that are on the boundaries of the current map.

The most obvious way is to loop through the entire array and check to see if the bounds contain marker boundaries, but this is not an efficient way to do this.

What data structure and / or algorithm can help solve the problem?

+3


source to share


1 answer


I would store the Latitude and Longitude values โ€‹โ€‹in some database and then give the database all the calculations. Then all you have to do is wait for the ajax response (which will take ~ 10 to 400ms) and then replace the tokens with the new ones that are returned in your request. Rendering 50 markers will be significantly faster than keeping track of the location of hundreds of thousands of markers on a map and also scrolling to see if they should appear or not. It also allows your single threaded Javascript to focus on the UI instead of complex computation.



0


source







All Articles