Google weather API change from F to C

[亡魂溺海] 提交于 2019-12-24 17:57:38

问题


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

回答1:


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']



来源:https://stackoverflow.com/questions/8059895/google-weather-api-change-from-f-to-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!