Sto cercando di restituire i marcatori come oggetto ma quando eseguo la funzione restituisce [], ma stampandolo all'interno posso vedere i dati dell'oggetto, qualcuno può spiegare come per restituire l'oggetto batch2 per favore?restituire oggetto da una funzione javascript con query di database all'interno di
google.maps.event.addListener(mgr, 'loaded', function(){
mgr.addMarkers(getMarkers(),6); //add all the markers! documentation for viewports with totals for city count, look at viewport
mgr.addMarkers(getMarkers2(),14); //get markers for zoomed out place, add click function to zoom in
//mgr.addMarkers(getMarkers(1000), 8);
console.log("added");
mgr.refresh();
});
function getMarkers2() {
var batch2 = [];
var clusters = new Parse.Query("cityfreqcoords");
var clusterresults = new Parse.Object("cityfreqcoords");
clusters.find({
success: function (results) {
for (i = 1; i < results.length; i++) {
var city = (results[i]["attributes"]["city"]);
var count = (results[i]["attributes"]["count"]);
var lat = (results[i]["attributes"]["lat"]);
var lng = (results[i]["attributes"]["lng"]);
var markerLatlong = new google.maps.LatLng(lat, lng);
//icon =
//adding the marker
var marker2 = new google.maps.Marker({
position: markerLatlong,
title: city,
clickable: true,
animation: google.maps.Animation.DROP
//icon:icon
});
//adding the click event and info window
google.maps.event.addListener(marker2, 'click', function() {
map.setZoom(6);
map.setCenter(marker2.getPosition());
});
batch2.push(marker2);
}
}
})
return batch2;
}
Hey grazie per la risposta, ho provato questo ed è ancora dando undefined –
@Ali_bean sì, il codice sta facendo alcune cose strane. Suggerirei di capire come funziona async e poi tornare ad esso. – Cymen
Darà un'occhiata in esso, grazie! Ho 5k markers e ho bisogno di essere in grado di utilizzare il gestore di marker –