Google 天气 API 从 F 更改为 C [英] Google weather API change from F to C

查看:42
本文介绍了Google 天气 API 从 F 更改为 C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将天气度数从华氏度更改为摄氏度时遇到了一些麻烦.

它只有在我改变当前天气程度时才正常工作,但在我改变预报时却没有.

有什么建议吗?

这是我的代码.

今天的天气

<div class="天气"><img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>"alt="天气"?><span class="条件"><?= $current[0]->temp_f['data'] ?>&deg;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'] ?>&deg;F - <?= $forecast->high['data'] ?>&deg;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'] ?>&deg; 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'] ?>&deg; F - <?= $forecast->high['data'] ?>&deg; 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屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆