Retrieve accurate weather information for any location in the world with Laravel and PHP
Want to get instant access to accurate weather data for any geo-point in the world? Let's use weather stack - one of the best services for getting weather information. The great thing is, this service is FREE to use!
What is weatherstack?
weatherstack is a good service that we can use to get years of historical weather data, request real-time weather information or make use of accurate weather forecasts. The service has been used by many popular companies around the world, such as Microsoft, Ericsson, Sneider, etc.
Features
Real-Time, History, Forecast
The API covers global weather data across the board — from a multi-year history all the way to live information and accurate weather forecasts.
Millions of Locations
Make use of live or hour-by-hour weather data for millions of cities and towns worldwide, supporting a variety methods to look up any location.
Rock-Solid Uptime & Speed
Powered by best-in-class cloud infrastructure, our API delivers data in milliseconds around the clock with an uptime of nearly 100%.
Start Free, Upgrade Later
Start testing the API immediately by signing up for the Free Plan. You can always upgrade later — no strings attached, no credit card required.
How to use
Register to get a free API key
You need to go to weatherstack and register to get a free API key.
Using PHP or Laravel
You can use raw PHP to get the weather data:
$location = 'New York';
$queryString = http_build_query([
'access_key' => 'YOUR_ACCESS_KEY',
'query' => $location,
]);
$ch = curl_init(sprintf('%s?%s', 'https://api.weatherstack.com/current', $queryString));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
$api_result = json_decode($json, true);
echo "Current temperature in $location is {$api_result['current']['temperature']}℃", PHP_EOL;
Documentation
Read the official documentation to learn code examples in different programming languages, all requesting and printing the latest available weather.
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 6 Laravel 5 Intermediate Sources Packages