douyan2680 2013-08-23 18:33
浏览 33

访客天气信息的PHP代码[关闭]

<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
// If we wanted to change the base currency, we would uncomment the following line
// $geoplugin->currency = 'EUR';

$geoplugin->locate();
echo "<p </span></p> </br>"; 
echo "<p style='text-align: center;'><span style='font-size: 50px; font-family: georgia,palatino; color: #202020 ;'> Your IP Address is {$geoplugin->ip} </span></p> </br>"; 
echo "<p style='text-align: center;'><span style='font-size: 16px; font-weight: bold; text-decoration: underline; font-family: georgia,palatino; color: #D67900;'> More Information About You </span></p>"; 
echo "<p style='text-align: center;'><span style='font-size: 13px; font-family: georgia,palatino; color: #686868;'> Your Country: {$geoplugin->countryName} | City: {$geoplugin->city} | Country Code: {$geoplugin->countryCode} | Longitudes: {$geoplugin->longitude} | Latitude: {$geoplugin->latitude} | Currency Code: {$geoplugin->currencyCode} | Currency Symbol: {$geoplugin->currencySymbol} </span>"; 
?>

I have the above code which will give me IP address along with city and county of the visitor. I need to find the weather condition of the city with this.

Here "{$geoplugin->city}" is giving me the city info.

  • 写回答

2条回答 默认 最新

  • dtwknzk3764 2013-08-23 18:41
    关注

    You'd need a weather API. Check out this one, The API docs are available here

    A PHP example using cURL:

    <?php
        $City = "London"; //Assign the city
        $APIKey = "42esgfa4pfqp6zwgr4egjbph"; //Assign the API key
            $WeatherRequest = curl_init(); //make a new cURL request
            curl_setopt_array($WeatherRequest, array(
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_URL => "http://api.worldweatheronline.com/free/v1/weather.ashx?q=".$City."&format=json&num_of_days=5&key=".$
            ));
            $Response = curl_exec($WeatherRequest); // execute the cURL request and get the reponse
            curl_close($WeatherRequest); // Close the request after we have received the response
            $JSON = json_decode($Response, true);
            //if using Celsius:
            echo($JSON["data"]["current_condition"]["temp_C"]);
            //if using fahrenheit:
            //echo($JSON["data"]["current_condition"]["temp_F"]);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图