Solucio temps

De wikiserver
Dreceres ràpides: navegació, cerca
<!DOCTYPE html>
<meta charset="UTF-8">
 
<form method="get" action="tiempo.php">
    <label>
        Ciudad
    </label>
    <input type = "text" name="c">
    <input type = "submit" value="Mostrar el Tiempo">
</form>


//arxiu temps

<?php 
 
if($_GET["c"]==null) die();
 
$html = file_get_contents("http://api.openweathermap.org/data/2.5/weather?q=".$_GET["c"]);
 
$json = json_decode($html);
 
$ciudad = $json->name;
$lat = $json->coord->lat;
$lon = $json->coord->lon;
$temp = $json->main->temp;
$tempmax = $json->main->temp_max;
$tempmin = $json->main->temp_min;
$presion = $json->main->pressure;
$humedad = $json->main->humidity;
$vel_viento = $json->main->temp;
$estado_cielo = $json->weather[0]->main;
$descripcion = $json->weather[0]->description;
 
echo "<h3>Ciudad: ".$ciudad." [lat = ".$lat. ", lon = ".$lon. " ]</h3>";
echo "<b>Estado del cielo: </b>".$estado_cielo."<br>";
echo "<b>Descripción: </b>".$descripcion."<br>";
echo "<br>";
echo "<b>Temperatura: </b>".$temp." K [Máx: ".$tempmax."K, Mín: ".$tempmin."K]<br>";
echo "<b>Presión: </b>".$presion."<br>";
echo "<b>Humedad: </b>".$humedad."<br>";
echo "<br><br><br><br><br>";  
?>

Exemple de json que retorna

{"coord":{"lon":2.16,"lat":41.39},"sys":{"type":3,"id":8549,"message":0.071,"country":"ES","sunrise":1427693836,"sunset":1427739255},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":{"temp":295.83,"pressure":1018,"temp_min":292.59,"temp_max":297.59,"humidity":84},"wind":{"speed":6.68,"gust":10.28,"deg":166},"rain":{"3h":0},"clouds":{"all":12},"dt":1427719945,"id":3128760,"name":"Barcelona","cod":200}