PHP Classes

WeatherStack PHP Class: Retrieve weather information from WeatherStack API

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 183 This week: 1All time: 8,675 This week: 560Up
Version License PHP version Categories
weatherstack 1.0.0GNU General Publi...5PHP 5, Web services, Geography
Description 

Author

This class can retrieve weather information from WeatherStack API.

It can send HTTP requests to the WeatherStack API Web server to retrieve several types of details about the weather of a location.

Currently it can return the current date weather information, historical weather information for past dates, weather forecast for future dates, and autocomplete the names of locations for which the weather is available.

Innovation Award
PHP Programming Innovation award nominee
September 2019
Number 3
Weather information is useful to know what is the expected weather for a region in a future date so people can get prepared.

However, in some cases it is also useful to know what was the weather of that region in a past date.

This class can provide past weather information using the WeatherStack API.

Manuel Lemos
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 58
All time rank: 618 in United States United States
Week rank: 20 Up3 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
/*
example usage
weatherStack ver 1.0

You must get an API key from https://weatherstack.com/product
and enter it in the weatherstack.class.php file
*/

//turning off low level notices
error_reporting(E_ALL ^ E_NOTICE);

//instantiate the class
include('weatherstack.class.php');
$weather = new weatherStack();

//set the end point to use
//free plan uses the 'current' endpoint
//we can set it with 'current' or 'c' shorthand
$weather->setEndPoint('c');

//set the query parameter
$weather->setParam('query','New York');

//optionally set the units
$weather->setParam('units','f');

//get the response
$weather->getResponse();

//show specific response data
echo 'The current temperature in '.$weather->response->location->name.', '
   
.$weather->response->location->region.' is '
   
.$weather->response->current->temperature
   
.' degrees ('.$weather->response->request->unit.')';

echo
'<hr>';

//displaying the full response
echo '<pre>';
var_dump($weather->response);
echo
'<pre>';

/*
Premium plans are available that allow access to more endpoints.
You can see what is available at https://weatherstack.com/product.
*/
?>


  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example Usage
Accessible without login Plain text file license.txt Lic. License
Plain text file weatherstack.class.php Class Main Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:183
This week:1
All time:8,675
This week:560Up
User Comments (2)
Well documented and works as described.
4 years ago (Rick Ruggiero)
70%StarStarStarStar
Cool implementation.
4 years ago (David Domingues)
45%StarStarStar