0

I'm creating a website that has has a map (bing maps or google maps doesn't matter) and the markers are requested every second from ajax and placed in the map.I have also a search input that if you type something the markers get filtered by that text.I described shortly with this code:

setInterval(function(){ getMarkers(); }, 1000); //checks for new makers every second

function getMarkers(){
    var markers = getAllMarkersByAjax($('#search').val()); //get markers from database by ajax request and by the text in the search input
    removeCurrentMarkers(); // loop that removes all the makrers
    addMarkers(markers); // loop that adds the new markers
}

Is this the best way?The markers can be to many im afraid that may be a lot of processing.Is there an efficient way to place the markers, filter them, performance?

Antonio Papa
  • 1,596
  • 3
  • 20
  • 38
  • you want to look at a marker clusterer, e.g. http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/ or http://google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/ – duncan Jan 22 '13 at 12:42
  • thats not the problem.The problem is the performance by removing and adding markers over and over – Antonio Papa Jan 22 '13 at 13:28
  • 1
    Rather than remove all markers, then add new markers, I'd try and see if you can work out just which ones need to be removed (assuming some of the current ones should remain after filtering). – duncan Jan 22 '13 at 13:55
  • yes i will try that but again must loop through markers.No other efficient way? – Antonio Papa Jan 22 '13 at 14:07
  • 1
    Assuming you have markers as an array, you could look for the difference between old and new, e.g. http://stackoverflow.com/a/4026828/492335 – duncan Jan 22 '13 at 15:01

0 Answers0