我在p5.js中创建了一个程序,它从API获取天气数据并将其可视化。不安全(HTTP)时,此代码在我的网站上正常工作,但在安全(HTTPS)时无法正常工作。这有什么理由/解决方案吗?
var weather;
var api = 'https://api.openweathermap.org/data/2.5/weather?q=';
var apiKey = '&APPID=021d86e44b1e37bd28f27baf523d920a';
var units = '&units=imperial';
function setup() {
createCanvas(400, 400);
var button = select('#submit');
button.mousePressed(weatherAsk);
input = select('#city');ff
}
function weatherAsk() {
var url = api + input.value() + apiKey + units;
loadJSON(url, gotData);
}
function gotData(data) {
weather = data;
}
function draw(){
background(255);
if (weather){
var temp = map(weather.main.temp, 32, 110, 0, 255);
var wind = map(weather.wind.speed, 0, 100, 0, 255);
var humid = map(weather.main.humidity, 0, 100, 0, 255)
var see = map(weather.visibility, 0, 29000, 0, 255)
noStroke();
fill(temp);
rect(0,0, 200,200)
fill(wind)
rect(200,0,200,200)
fill(humid)
rect(0,200,200,200)
fill(see)
rect(200,200,200,200)
fill(255)
textStyle(ITALIC)
textAlign(CENTER);
textSize(10)
fill(temp-255);
text("temperature",100,100)
fill(255)
text("wind speed", 300, 100)
fill(255)
text("humidity", 100,300)
fill(255)
text("visibility", 300,300)
}
}