I am using Datamaps, and have a JSON file of coordinates I wish to map. I am having issues making functions wait for each other. Why is it that one finishes before even calling the functions that are in its body?
Here are some code snippets trying to get a list of longitude values:
$(document).ready(function make_bubbles() {
list = parse_data();
})
function parse_data(){
var longitude = new Array();
make_array(longitude);
return longitude;
}
function make_array(input_list){
d3.json("data/parsed_book_data.json",function(error,data){
if (error) return console.warn(error);
for(var i = 0; i < data.length; i++)
{
if(data[i]["lng"]) {
input_list[i] = data[i]["lng"];
}
}
});
}
Update: After tweaking the above functions, I now have...
$(document).ready(function make_bubbles() {
var list;
list = parse_data();
console.log(list + "SIZE: " +list.length)
}
And it prints out the list in the console, but it says the size is 0, why is this?