Question

I have a new website that will need to display a water display in a div

I'd like to display :

  • place name
  • weater in c or f
  • icon
  • text of what the icon mean

I need to get weather from CANADA (QUEBEC) it must look like : havre-saint-pierre : aujourdhui : 18c, passages nuageux

Where and how can I get a up-to-date stream of weather data?

Was it helpful?

Solution

Forget yahoo, the most easy and fast way to do that is with google weather API, you didnt specify what programing skill you have, so i will asume you know php and html, here is your code:

<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');
$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><?= print $information[0]->city['data']; ?></h1>
        <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 ?>
    </body>
</html>

Good luck!

OTHER TIPS

Yahoo has a feed - it's RSS, and not JSON - but it's always up to date and very simple to use. You can find more details here:

http://developer.yahoo.com/weather/

this is also a good response/answer : Parse weather data from Weatherbug in PHP

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top