Ajax is asynchronous. What happened, you created MarkerClusterer before the callback function ended, and thus the marker was not placed in the markersArray global array. It's just on my head without any testing, but see if it solves the problem.
var markersArray = [], markerCluster;
function getMarkers(hours) {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
image = '/images/site/tw.png';
$.ajax({
url: "updateMarkers",
type:"POST",
data:{"hours": hours},
success: function(data){
data = $.parseJSON( data );
if (data.Locations.length>0) {
for (i=0; i<data.Locations.length; i++) {
loc = new google.maps.LatLng(data.Locations[i].lat, data.Locations[i].lng);
marker = new google.maps.Marker({
position: loc,
map: map,
icon: image,
html: content
});
markersArray.push(marker);
infowindow = new google.maps.InfoWindow({
content: "holding..."
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, this);
infowindow.setContent(this.html);
});
}
markerCluster = new MarkerClusterer(map, markersArray);
}
}
});
}
getMarkers(24);
source
share