<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="../geonames.js"></script>
<script type="text/javascript" src="http://www.thomasfrank.se/SQLike/js/SQLike.js"></script>
<script type="text/javascript">
htmlTable=function(json){
if(!json){return};
var x,header="",content="", colNames={},colAlign={};
for(var i=0;i<json.length;i++){
for(var j in json[i]){
colNames[j]=1
json[i][j]==json[i][j]/1 && (colAlign[j]=1)
}
}
for(var i=0;i<json.length;i++){
content+='<tr>';
for(var j in colNames){
if(!i){
header+='<td style="'+(colAlign[j]?'text-align:right;':'')+'background:#666;color:#fff"><b>'+j+'</b></td>'
};
content+='<td style="background:'+(i%2==0?'#ddd':'#fff')+'" '+(colAlign[j]?'align="right"':'')+'>'+(json[i][j]+"").replace(/ /g,' ')+'</td>'
};
content+='</tr>'
}
x='<table cellspacing=1 cellpadding=3 border=0 width="710"><tr>'+
header+'</tr>'+content+'</table>';
return x
};
</script>
<script type="text/javascript">
var w = new geonames({
service: "cities",
options: {
north: 50, south:20, east:15, west: 0
},
culture: "DE",
apikey: "demo"
});
w.getData(function(data){
var dataTable = data.geonames;
console.log(data);
if(data.status.value==18){
alert("Invalid api key. Please register at geonames.org first.");
} else {
var rs=SQLike.q({
Select: ['*'],
From: dataTable,
OrderBy: ['name','|asc|']
});
var tbl=htmlTable(rs);
function createDiv(html){
var _body = document.getElementsByTagName('body') [0];
var _div = document.createElement('div');
_div.innerHTML=html;
_body.appendChild(_div);
}
createDiv(tbl);
}
});
</script>
</head>
<body>
</body>
</html> |