vemcogroup/laravel-weather
Composer 安装命令:
composer require vemcogroup/laravel-weather
包简介
Weather package for Laravel to use different providers to get weather info
README 文档
README
Description
This package allows you to fetch weather data from different weather providers
Installation
You can install the package via composer:
composer require vemcogroup/laravel-weather
The package will automatically register its service provider.
To publish the config file to config/weather.php run:
php artisan vendor:publish --provider="Vemcogroup\Weather\WeatherServiceProvider"
The default configuration can be seen here
Usage
At the moment this package support the following weather services, you can update WEATHER_PROVIDER to one of the following
| Service | Provider name | Website | Geocoding | Remarks |
|---|---|---|---|---|
| Dark Sky | darksky | https://darksky.net | Manual | Deprecated, not able to acquire api key https://blog.darksky.net. Will continue to function until March 31st, 2023. |
| Weatherstack | weatherstack | https://weatherstack.com | Auto | For historical data a minimum Standard license is required. For forecast data a minimum Professional license is required. |
| WeatherKit | weatherkit | https://developer.apple.com/weatherkit/ | Auto | Needs an apple developer account. |
For other weather services fill free to create an issue or make a Pull Request.
For Manual geocoding you need a Google geocode api key.
Acquire it here https://developers.google.com/maps/documentation/geocoding/start and insert it into your .env file.
GOOGLE_MAPS_GEOCODING_API_KEY=
Request
Start by setting up your request
$request = (new Vemcogroup\Weather\Request('1 Infinite Loop, Cupertino, CA 95014, USA'));
By default, it caches the weather response for 24hrs (86.400sec), this can be changed by setting a second parameter to cache timeout (in seconds)
$request = (new Vemcogroup\Weather\Request('1 Infinite Loop, Cupertino, CA 95014, USA', 600));
Units
There two available unit types, default is Metric:
Metric (m): Vemcogroup\Weather\Providers\Provider::WEATHER_UNITS_METRIC
Fahrenheit (f): Vemcogroup\Weather\Providers\Provider::WEATHER_UNITS_FAHRENHEIT
To change the response units you can do the following:
$request->withUnits(Vemcogroup\Weather\Providers\Provider::WEATHER_UNITS_FAHRENHEIT);
Locale
To change the locale for descriptions, summaries and other texts in the response, do the following:
$request->withLocale('nl');
Locale need to be an 2-letter ISO Code of your preferred language.
Dates If you need to select the dates to get weather data for E.g for historical data, set the dates like this:
$request->withDates([$date, ...]);
All dates in the array need to Carbon objects.
Options
If you need to set any extra options based in your selected weather provider you can do the following:
$request->withOption('name', 'value');
Current weather and forecast
To get current weather and forecast response you can do this:
$weather = weather()->getForecast($request);
Weather response will always be a Collection of responses.
Forecast days depends on weather service provider.
To get current weather data:
$weather->first()->getCurrently(); // DataPoint
To get forecast you can take first element of response and get the forecast like this:
$weather->first()->getDaily()->getData(); // array
Afterward run through the array with represent each day of the forecast on a DataPoint object.
Historical
To get historical data you can do this:
$weather = weather()->getHistorical($request);
Remember to set dates on request.
Response will be a collection with keys representing the dates for historical data.
Response
To see what response data is available look into source code /src/Objects
vemcogroup/laravel-weather 适用场景与选型建议
vemcogroup/laravel-weather 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.36k 次下载、GitHub Stars 达 55, 最近一次更新时间为 2020 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「weather」 「darksy」 「weatherstack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vemcogroup/laravel-weather 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vemcogroup/laravel-weather 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vemcogroup/laravel-weather 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel-forecast provides a service provider and a facade around the Forecast-php wrapper
Add a weather widget to Flarum
Simple weather forecaster for Laravel
Alfabank REST API integration
Unofficial PHP client for aWhere weather API
Anax weather module
统计信息
- 总下载量: 26.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 56
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-30