1. Go to this page and download the library: Download amwhalen/noaa library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amwhalen / noaa example snippets
$config = new \noaa\weather\Configuration();
$myWritableCacheDirectory = dirname(__FILE__) . '/cache';
$config->setCache(new \noaa\weather\cache\FileCache($myWritableCacheDirectory));
$forecaster = new \noaa\Forecaster($config);
$stationId = 'KBAF';
try {
// returns a CurrentWeather object or throws an exception on API error
$current = $forecaster->getCurrentWeather($stationId);
} catch (\Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
echo "Temperature: " . $current->getTemperatureF() . " °F\n";
$config = new \noaa\weather\Configuration();
$myWritableCacheDirectory = dirname(__FILE__) . '/cache';
$config->setCache(new \noaa\weather\cache\FileCache($myWritableCacheDirectory));
$forecaster = new \noaa\Forecaster($config);
$lat = '42.16';
$lng = '-72.72';
$startTime = date('Y-m-d', time());
$numDays = 7;
try {
// returns a Forecast object or throws an exception on API error
$forecast = $forecaster->getForecastByLatLng($lat, $lng, $startTime, $numDays);
} catch (\Exception $e) {
echo "There was an error fetching the forecast: " . $e->getMessage() . "\n";
}
// get ForecastDay object for the first day of the forecast
$day = $forecast->getDay(0);
echo "High Temperature: " . $day->getHighTemperature() . "\n";
$forecast->doesStartAtNight();
if ($forecast->doesStartAtNight()) {
$tonightsPrecipitation = $forecast->getPrecipitationProbabilityTonight();
}
$forecaster = new \noaa\Forecaster();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.