I am new to this platform and also in coding.I am trying to get AQI using REST API from a server. It works fine when I am giving the latitude and longitude value directly to the API. But it is giving bad request 400 error when I am passing latitude and longitude value as a variable. Please help me.
My code snippet are as bellow
var aqival;
var level;
var sval;
var arrf;
var latitude =parseFloat(22.569719);
var longitude =parseFloat(88.36972);
var request = new XMLHttpRequest();
request.open("GET", "https://api.weatherbit.io/v2.0/current/airquality?lat=latitude&lon=longitude&key=API KEY", true);
console.log(latitude);
console.log(typeof(latitude));
request.onload = function () {
var jsonobj = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
aqival = jsonobj.data[0].aqi;
level = "poor";
} else {
console.log('error');
}
var arr = "kolkata,wb";
var arrpad = arr.padEnd(23,' ');
sval = String(aqival);
var valpad = sval.padEnd(4,' ');
var levelpad = level.padEnd(6,' ');
arrf = arrpad + valpad + leve`enter code here`lpad;
console.log(arrf);
// Begin accessing JSON data here
}
request.send();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…