I am having trouble with a seemingly simple problem. I am pulling data from an external JSON file and need to loop through all the objects and return their values to use in another function. Here is what I have so far...
var geo;
function getCountry(){
$.getJSON('country.json', function(res) {
return $.each(res, function(key, val) {
for(var i = 0; i < val.length; i++) {
geo = val[i].geometry.coordinates;
return geo;
}
})
});
}
function mapIt() {
getCountry();
$(".container").mapael({
map : {
name : "world_countries", // name of JS file
},
plots: {
'Random': {
latitude: geo[0],
longitude: geo[1]
}
}
});
}
mapIt();
Essentially, I am getting the latitude and longitude of a specific country with the first function and am trying to return the value (geo, which is an array containing the lat/long) and use it in the second function. I thought that I could maybe call the getCountry function within the mapIt function and it would store the variable.
Any suggestions/help would be greatly appreciated thank you so much!
Aucun commentaire:
Enregistrer un commentaire