谷歌API的天气变化从F到Ç [英] Google weather API change from F to C
本文介绍了谷歌API的天气变化从F到Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是个有点麻烦改变天气度至华氏摄氏。
其工作正确的,只有当我改变当前的天气程度,但不是当林changen的预测。
任何建议吗?
这是我的code。
< H2>今天的天气和LT; / H>
< DIV CLASS =天气>
< IMG SRC =< ='http://www.google.com'$电流[0] - >?图标['数据']>? ALT =天气&GT?;
<跨度类=条件>
?&所述; = $电流[0] - GT; temp_f ['数据']≥&放大器;度;? F,
< = $电流[0] - >有状态['数据']>
< / SPAN>
< / DIV>
< H2>预测及LT; / H>
&LT ;?的foreach($ forecast_list为$预测):>
< DIV CLASS =天气>
< IMG SRC =< ='http://www.google.com'$以下预测方式>图标['数据']>? ALT =天气&GT?;
< DIV>< = $以下预测> DAY_OF_WEEK ['数据']; ?>< / DIV>
<跨度类=条件>
< = $以下预测>低['数据']>&安培;度;的F - <?= $以下预测>高['数据']>&安培;度; F,
< = $以下预测>条件['数据']>
< / SPAN>
< / DIV>
&LT ;? endforeach&GT?;
解决方案
函数toCelsius($度){
返回($度-32)/1.8;
}
如果F中的温度是在这里: $电流[0] - > temp_f ['数据']
然后,所有你需要做的是这样的: toCelsius($电流[0] - > temp_f ['数据']
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']
这篇关于谷歌API的天气变化从F到Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文