【问题标题】:Google weather API change from F to CGoogle 天气 API 从 F 更改为 C
【发布时间】:2011-12-24 23:37:52
【问题描述】:

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

只有当我改变当前天气程度时它才能正常工作,但当我改变预测时它就不行了。

有什么建议吗?

这是我的代码。

<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 ?>

【问题讨论】:

标签: php api google-weather-api


【解决方案1】:
function toCelsius($deg) {
    return ($deg-32)/1.8;
}

如果您在 F 中的温度在这里:$current[0]-&gt;temp_f['data']

那么你所要做的就是:toCelsius($current[0]-&gt;temp_f['data']

【讨论】:

    猜你喜欢
    • 2011-06-25
    • 1970-01-01
    • 2018-03-12
    • 2019-05-28
    • 2016-05-28
    • 2013-01-15
    • 2012-03-29
    • 1970-01-01
    • 2014-02-23
    相关资源
    最近更新 更多