我正在尝试通过 OpenWeather API 服务获取坐标的时区。我想将坐标存储在一个变量中,但我无法这样做。谁能帮帮我....
代码:
fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lng}&appid=e7e85587bd54ecf4c0ff04af357ae122`)
.then(response => response.json())
.then(data => {
var tz = ((data.timezone) / 3600); //I'm not able to access tz outside fetch...
// addr.innerHTML = data.address.county+", "+data.address.state_district+", "+data.address.state+", "+data.address.country;
})
.catch(error => {
console.error('Error:', error);
});
tz 仅在 fetch 内存储和打印,而不是在外部......