As the title says, even though it may be a little bit vague, when i call a function which returns an array of objects in another function, for some reason i'm not able to catch the result in another object in the current function. I have a feeling that is just a little thing that i'm missing.
Here is the function which returns the array of objects :
function GetAllNeighboors(myLocationLat, myLocationLong) {
$.get("/Home/GetAllLocation",
function (data, status) {
Neightbours = new Object();
var j = 0;
for (var i = 0; i < data.length; i++) {
if (distanceBetweenTwoStations(myLocationLat, myLocationLong, data[i].latitudine, data[i].longitudine,"K") <= 1 && data[i].latitudine != myLocationLat && data[i].longitudine != myLocationLong) {
Neightbours[j] = data[i];
j++;
}
}
return Neightbours;
});
}
And here is where i'm calling that function:
if (data.isClosed != true) {
map.setCenter(new google.maps.LatLng(data.latitudine, data.longitudine));
map.setZoom(17);
} else {
Vecini = new Object();
Vecini = GetAllNeighboors(data.latitudine, data.longitudine);
NOTE: The Neightbours
from the first function comes with the expected result.
NOTE2: I think i figured out what is the problem, but i'm not really sure how i can solve it. The problem is i'm not waiting for the result, i should make the function asynchronous, in order to have the result in the second function. Any idea how i can do that?