-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
58 lines (50 loc) · 1.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="data"></div>
<script>
var apiMethod = 'countryInfoJSON';
var parameters = 'username=yourUsername';
var result = '';
var countries = {};
$.get('http://api.geonames.org/' +
apiMethod + '?' + parameters, function (data) {
console.log(data["geonames"]);
$.each(data['geonames'], function (i, item) {
countries[item.countryCode] = {id: item.geonameId};
countries[item.countryCode].neighbours = [];
});
var count = 1;
var allowed = 3;
var accessed = 0;
var countryLen = Object.keys(countries).length;
$.each(countries, function (i, item) {
console.log(i);
// if(accessed++<allowed){
$.get('http://api.geonames.org/neighboursJSON?geonameId=' + item["id"] + '&' + parameters, function (data) {
if (data["geonames"]) {
$.each(data["geonames"], function (j, it) {
if (it.fcl == "A") {
countries[i].neighbours.push(it.countryCode);
}
});
}
console.log(count);
if (count++ == countryLen) {
printResults();
}
});
// }
});
printResults = function () {
result = JSON.stringify(countries);
$('#data').html(result);
console.log(countries);
}
});
</script>
</body>
</html>