PHP Classes

PHP Open Weathermap: Get the weather for a given location

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 366 All time: 6,845 This week: 524Up
Version License PHP version Categories
weathermap 4BSD License5PHP 5, Web services, Weather
Description 

Author

This package can get the weather for a given location.

It can send a HTTP request to the OpenWhethermap API Web server to retrieve the current weather conditions at a location with given latitude and longitude.

The class can return the weather conditions described using English text.

Picture of Marcel Kohls
  Performance   Level  
Name: Marcel Kohls <contact>
Classes: 2 packages by
Country: Brazil Brazil
Age: 43
All time rank: 3186235 in Brazil Brazil
Week rank: 301 Up25 in Brazil Brazil Up

Example

<?php
   
require_once('Weather.class.php');
   
   
$weather = new Weather();
   
   
$weather->latitude = "-26.984500";
   
$weather->longitude = "-48.631668";
   
$weather->unit = "C"; // units can be: "F" for Fahrenheit, "C" for Celsius, "K" for Kelvin
   
$weather->apiKey = "api-code-here";
   
   
    if (
$weather->loadWeather() == true){
        echo
'weather now is: <br />';
        echo
$weather->general.'<br />';
        echo
'('.$weather->detailed.')<br />';
        echo
'<img src="http://openweathermap.org/img/w/'.$weather->icon.'.png"><br />';
        echo
$weather->temperature.' '.$weather->unit.' <br /> ';
        echo
'min.:'.$weather->temp_min.' / max.:'.$weather->temp_min.'<br />';
        echo
'pressure: '.$weather->pressure.' hpa<br /> ';
        echo
'humidity: '.$weather->humidity.'% <br /> ';
       
//hpa
   
}
?>


  Files folder image Files  
File Role Description
Accessible without login Plain text file index.php Example index file, demo
Plain text file Weather.class.php Class main class for weather object
Plain text file WeatherCondition.class.php Class support class for weather descriptions

 Version Control Unique User Downloads Download Rankings  
 0%
Total:366
This week:0
All time:6,845
This week:524Up