How do I make this function return the entire array when it's done pushing all markers?
function XTW_getLocations(data, div_id, map) {
var markers = [];
var marker;
var latLngBounds = new google.maps.LatLngBounds();
$(div_id).empty();
$.getJSON('GetLocations', "country=" + data.id,
function(data){
$.each(data, function(index, data) {
latLngBounds.extend(new google.maps.LatLng(data.location.latitude, data.location.longitude));
$(div_id).append( new Option(data.name, data.id ) );
marker = createMarker(data, icon, html, map);
markers.push(marker);
});
map.fitBounds(latLngBounds);
});
return markers;
}