I'm attempting to add my markers to a MarkerCluster, I have the following code, I push each Marker
to the markers
array. I then declare markerCluster
and add in the markers
array and the map. However my MarkersClusterer never display, could anyone suggest why this is?
map = new google.maps.Map($('#map_canvas')[0], myOptions);
infowindow = new google.maps.InfoWindow();
markerCluster = new MarkerClusterer(map, markers);
//do ajax request, add marker on success
jQuery.post(ajaxurl, data, function(response) {
for (key in response) {
if(response[key]["post_code"] === undefined ){
return;
}
(function () {
var markers = [];
var address = response[key]["address"];
$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+response[key]["post_code"]+'&sensor=false', null, function (data) {
var p = data.results[0].geometry.location
var latlng = new google.maps.LatLng(p.lat, p.lng);
var Marker = new google.maps.Marker({
position: latlng,
map: map,
content: address
});
markers.push(Marker);
google.maps.event.addListener(Marker, 'click', function () {
infowindow.setContent(this.content);
infowindow.open(map, this);
});
});
})();
};
});