Google 天气 API 从 F 更改为 C [英] Google weather API change from F to C
问题描述
我在将天气度数从华氏度更改为摄氏度时遇到了一些麻烦.
它只有在我改变当前天气程度时才正常工作,但在我改变预报时却没有.
有什么建议吗?
这是我的代码.
今天的天气
<div class="天气"><img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>"alt="天气"?><span class="条件"><?= $current[0]->temp_f['data'] ?>°F,<?= $current[0]->condition['data'] ?></span>
<h2>预测</h2><?foreach ($forecast_list as $forecast) : ?><div class="天气"><img src="<?= 'http://www.google.com' . $forecast->icon['data']?>"alt="天气"?><div><?= $forecast->day_of_week['data'];?></div><span class="条件"><?= $forecast->low['data'] ?>°F - <?= $forecast->high['data'] ?>°F,<?= $forecast->condition['data'] ?></span>
<?Endforeach ?>
function toCelsius($deg) {回报 ($deg-32)/1.8;}
如果你的温度 F 在这里:$current[0]->temp_f['data']
那么你所要做的就是:toCelsius($current[0]->temp_f['data']
Im having a bit of trouble changing the the weather degrees from fahrenheit to celcius.
Its working correct only when I change the current weather degree but not when Im changen the forecast.
Any sugestions ?
this is my code.
<h2>Today's weather</h2>
<div class="weather">
<img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?= $current[0]->temp_f['data'] ?>° F,
<?= $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<? foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?= $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?= $forecast->low['data'] ?>° F - <?= $forecast->high['data'] ?>° F,
<?= $forecast->condition['data'] ?>
</span>
</div>
<? endforeach ?>
function toCelsius($deg) {
return ($deg-32)/1.8;
}
If your temperature in F is here: $current[0]->temp_f['data']
Then all you have to do is this: toCelsius($current[0]->temp_f['data']
这篇关于Google 天气 API 从 F 更改为 C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!