Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌天气预报计算问题_Php_Xml_Google Api_Google Weather Api - Fatal编程技术网

Php 谷歌天气预报计算问题

Php 谷歌天气预报计算问题,php,xml,google-api,google-weather-api,Php,Xml,Google Api,Google Weather Api,这是关于这个问题的 谷歌在做什么计算 当我用weather=London,UK关键字在谷歌上搜索时,它会显示类似于此屏幕截图的内容 在我的XML中没有26、11、26、22之类的 我的XML如下所示 天气预报中的计算是什么 如何将这些输入PHP变量?没有计算。链接的XML具有以下节点: <temp_f data="70"/> <temp_c data="21"/> 没有计算。链接的XML具有以下节点: <temp_f data="70"/> <t

这是关于这个问题的

谷歌在做什么计算

当我用weather=London,UK关键字在谷歌上搜索时,它会显示类似于此屏幕截图的内容

在我的XML中没有26、11、26、22之类的

我的XML如下所示

天气预报中的计算是什么


如何将这些输入PHP变量?

没有计算。链接的XML具有以下节点:

<temp_f data="70"/>
<temp_c data="21"/>

没有计算。链接的XML具有以下节点:

<temp_f data="70"/>
<temp_c data="21"/>

谷歌天气API
今天的天气
图标['data']?>“alt=”天气“?>
&摄氏度,
预测
图标['data']?>“alt=”天气“?>
&度;C-°;C

谷歌天气API
今天的天气
图标['data']?>“alt=”天气“?>
&摄氏度,
预测
图标['data']?>“alt=”天气“?>
&度;C-°;C

实际上,将&hl=en GB添加到URL的末尾就很容易了 应该有用。
其他语言也存在解析问题(与UTF-8相关),但对于英语来说,要转换到摄氏度,只需切换到GB语言环境(默认设置为US)。

实际上,这就像在URL末尾添加&hl=en GB一样简单 应该有用。
对于其他语言,存在解析问题(与UTF-8相关),但对于英语,要转换为摄氏度,只需切换到GB语言环境(默认设置为US)。

正如AR所解释的,返回摄氏度值与传递语言代码一样简单

Google weather API没有官方文档,但我发现以下两个链接很有用:

  • (查看来源以查看天气返回类型列表)

正如AR所解释的,返回摄氏度值实际上就像传递语言代码一样简单

Google weather API没有官方文档,但我发现以下两个链接很有用:

  • (查看来源以查看天气返回类型列表)

您有更好的图片吗,我们可以看到文件的内容。您有更好的图片吗,我们可以看到文件的内容。我应该使用或@Bharanikumar吗?正如解释的那样:温度数据已经是华氏温度,所以您不需要转换温度数据。你必须转换成低和高。显然,谷歌会根据语言的不同而改变语言和温度单位。您可以通过向URL添加附加参数来强制使用特定语言。你可能想考虑使用它。我应该使用或@ BaRaNikuMar来解释:TimeFif数据已经是华氏温度计,所以你不需要转换TEMPUSTC数据。你必须转换成低和高。显然,谷歌会根据语言的不同而改变语言和温度单位。您可以通过向URL添加附加参数来强制使用特定语言。你可能想考虑使用。
            from Fahrenheit               to Fahrenheit
Celsius     [°C] = ([°F] − 32) × 5⁄9      [°F] = [°C] × 9⁄5 + 32
    <?php
        $xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
        $information = $xml->xpath("/xml_api_reply/weather/forecast_information");
        $current = $xml->xpath("/xml_api_reply/weather/current_conditions");
        $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
    ?>
    <html>
    <head>
        <title>Google Weather API</title>
    </head>
    <body>
        <h1><?php print $information[0]->city['data']; ?></h1>
        <h2>Today's weather</h2>
        <div class="weather">
            <img src="<?php echo  'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
            <span class="condition">
            <?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>&deg; C,
            <?php echo $current[0]->condition['data'] ?>
            </span>
        </div>
        <h2>Forecast</h2>
        <?php foreach ($forecast_list as $forecast) : ?>
            <div class="weather">
                <img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
                <div><?php echo $forecast->day_of_week['data']; ?></div>
                <span class="condition">
                    <?php echo round(conver_f_c($forecast->low['data'])); ?>&deg; C - <?php echo round(conver_f_c($forecast->high['data'])); ?>&deg; C,
                    <?php echo $forecast->condition['data'] ?>
                </span>
            </div>
        <?php endforeach ?>
    </body>
</html>

<?php
function conver_f_c($F){

    return  $C = ($F - 32) * 5/9;
}