Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get weather at current location

Possible duplicate:

Get weather update of current location?

How can I get the weather in current location from Latitude and Longitude?

I'm developing an app, it can update weather at current location. I have googled and found how to use Google API. But now Google API not available, and I used Yahoo weather instead.

My questions:

  1. How to get weather use Yahoo Weather API

  2. Tutorial or Source Code

like image 992
Tuan Vu Avatar asked Mar 15 '13 05:03

Tuan Vu


2 Answers

I have personally used this API its free and you can retrieve weather forecast for any location via postcode, zipcode or latitude and longitude

Free Local Weather REST API

**NOTE:**The Local Weather API returns weather data in XML, JSON and CSV format and contains weather elements like temperature, precipitation (rainfall), weather description, weather icon and wind speed.

**UPDATE:**The www.worldweatheronline.com/ api is not free anymore.

Try these

  1. accuweather.com
  2. https://openweathermap.org/
  3. www.apixu.com
like image 40
Amitabh Sarkar Avatar answered Nov 15 '22 23:11

Amitabh Sarkar


I have personally used OpenWeather API. its totally free and you can retrieve weather forecast for any location via city name, zipcode or latitude and longitude etc.

<?php
 $city    = 'london';
    $jsonfile    = file_get_contents( 'http://api.openweathermap.org/data/2.5/weather?q=' . $city . '&units=metric&lang=en&appid=c0c4a4b4047b97ebc5948ac9c48c0559' );
    $jsondata    = json_decode( $jsonfile );
    $temp        = $jsondata->main->temp;
    $pressure    = $jsondata->main->pressure;
    $mintemp     = $jsondata->main->temp_min;
    $maxtemp     = $jsondata->main->temp_max;
    $wind        = $jsondata->wind->speed;
    $humidity    = $jsondata->main->humidity;
    $desc        = $jsondata->weather[0]->description;
    $maind       = $jsondata->weather[0]->main;
    $currentTime = time();
    ?>
    <style>
    body {
        font-family: Arial;
        font-size: 0.95em;
        color: #929292;
    
    }
    
    .report-container {
        border: #E0E0E0 1px solid;
        padding: 20px 40px 40px 40px;
        border-radius: 2px;
        width: 550px;
        margin: 0 auto;
    }
    
    .weather-icon {
        vertical-align: middle;
        margin-right: 20px;
    }
    
    .weather-forecast {
        color: #212121;
        font-size: 1.2em;
        font-weight: bold;
        margin: 20px 0px;
    }
    
    span.min-temperature {
        margin-left: 15px;
        color: #929292;
    }
    
    .time {
        line-height: 25px;
    }
    </style>
    <body>
    <div class="report-container">
            <h2><?php echo $jsondata->name; ?> Weather Status</h2>
            <div class="time">
                <div><?php echo date( 'l g:i a', $currentTime ); ?></div>
                <div><?php echo date( 'jS F, Y', $currentTime ); ?></div>
                <div><?php echo $desc; ?></div>
            </div>
            <div class="weather-forecast">
                <img
                    src="http://openweathermap.org/img/w/<?php echo $jsondata->weather[0]->icon; ?>.png"
                    class="weather-icon" /> <?php echo $mintemp; ?>°C<span
                    class="min-temperature"><?php echo $maxtemp; ?>°C</span>
            </div>
            <div class="time">
                <div>Humidity: <?php echo $humidity; ?> %</div>
                <div>Wind: <?php echo $wind; ?> km/h</div>
            </div>
        </div>
        </body>
like image 58
Devsaiful Avatar answered Nov 15 '22 23:11

Devsaiful