> So I try to put this 3 lines in my function loadmap : > > var markers = []; > markers.push(marker); > var markerCluster = new MarkerClusterer(map, markers);
It's going to be very difficult if you don't think about what you are telling the code to do. Where you put code in the order of events is just as important as what the code does. So, in loadMap() ... > var markers = []; This will create an array called 'markers' It is in local scope and won't be available after loadMap() has completed. You already have a global array called 'gmarkers' so I don't know what this one is for at all. > markers.push(marker); You have this line before you have created any markers at all, so it won't do anything useful. That is what the script error was telling you. Even if it did something, it wouldn't be very helpful as it would add one marker to your array. You ought to be doing this inside the loop where you are creating many markers, one at a time. So that as each marker is created, it will be added to the array. > var markerCluster = new MarkerClusterer(map, markers); Again, this is before any markers have been created at all. As you would like to pass in the markers that you want MarkerClusterer to manage for you, it will work much better if you do this after all the markers have been created and a copy of each one saved into whichever array you choose to save them in and pass to the clusterer. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
