gitwa2/hero-open-weather-php
Composer 安装命令:
composer require gitwa2/hero-open-weather-php
包简介
A simple PHP package to fetch weather data using latitude and longitude.
README 文档
README
A simple PHP package to fetch weather data using latitude and longitude.
Installation
You can install this package via Composer:
composer require gitwa2/hero-open-weather-php:dev-main
Usage
Importing the Package
To use the hero-open-weather-php package in your project, you need to include the Composer autoloader.
require 'vendor/autoload.php'; use HeroOpenWeather\WeatherClient;
Fetching Weather Data
You can fetch the weather data by providing the latitude and longitude.
require 'vendor/autoload.php'; use HeroOpenWeather\WeatherClient; $latitude = 35.6895; // Example: Latitude for Tokyo $longitude = 139.6917; // Example: Longitude for Tokyo $weatherClient = new WeatherClient(); try { $weatherData = $weatherClient->getWeather($latitude, $longitude); echo "Weather Data:\n"; foreach ($weatherData['hourly']['time'] as $index => $time) { echo "Time: $time, Temperature: {$weatherData['hourly']['temperature_2m'][$index]}°C\n"; } } catch (Exception $e) { echo $e->getMessage(); }
Example Response
Here's an example of the response data you might receive:
{
"latitude": 35.6895,
"longitude": 139.6917,
"generationtime_ms": 1.5,
"utc_offset_seconds": 0,
"timezone": "UTC",
"hourly_units": {
"time": "iso8601",
"temperature_2m": "°C"
},
"hourly": {
"time": [
"2024-08-04T00:00:00Z",
"2024-08-04T01:00:00Z",
"2024-08-04T02:00:00Z"
// more timestamps
],
"temperature_2m": [
25.3,
24.8,
24.1
// more temperatures
]
}
}
Author
Milad Davoodabadi (milad.davoodabadi@outlook.com)
License
This project is licensed under the ISC License.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2024-08-04