bioudi / laravel-meta-weather-api
🌦 简单的 laravel 包,用于调用 MetaWeather API。
v0.1.2-alpha
2019-08-25 00:00 UTC
Requires
- guzzlehttp/guzzle: ^6.3
This package is auto-updated.
Last update: 2024-09-13 04:59:29 UTC
README
简单的 laravel 包,用于调用 MetaWeather API。
MetaWeather API 示例
请注意,MetaWeather API 不需要任何形式的认证。请参阅MetaWeather API 文档以获取所有支持的方法和参数。
重要:API 不支持 CORS。
安装
要获取项目中 laravel-meta-weather-api 的最新版本,请从 "composer" 中引入它
$ composer require bioudi/laravel-meta-weather-api
Laravel
直接在您的 app 配置文件 config/app.php 中注册提供者 config/app.php
'providers' => [ // ... Bioudi\LaravelMetaWeatherApi\WeatherserviceProvider::class ]
用法
use Bioudi\LaravelMetaWeatherApi\Weather; $weather = new Weather();
通过城市名称搜索
$weather->getByCityName('casablanca');
输出
{ "consolidated_weather": [ { "id": 6739825128374272, "weather_state_name": "Light Cloud", "weather_state_abbr": "lc", "wind_direction_compass": "NE", "created": "2019-03-24T10:23:58.103425Z", "applicable_date": "2019-03-24", "min_temp": 11.86, "max_temp": 24.58, "the_temp": 23.2, "wind_speed": 4.869768947042604, "wind_direction": 35.5, "air_pressure": 1014.9549999999999, "humidity": 56, "visibility": 13.852227988546886, "predictability": 70 } ], "time": "2019-03-24T11:40:48.477916Z", "sun_rise": "2019-03-24T06:29:23.305030Z", "sun_set": "2019-03-24T18:44:48.967938Z", "timezone_name": "LMT", "parent": { "title": "Morocco", "location_type": "Country", "woeid": 23424893, "latt_long": "31.434200,-6.402450" }, "sources": [ { "title": "BBC", "slug": "bbc", "url": "http://www.bbc.co.uk/weather/", "crawl_rate": 180 }, { "title": "Forecast.io", "slug": "forecast-io", "url": "http://forecast.io/", "crawl_rate": 480 }, { "title": "Met Office", "slug": "met-office", "url": "http://www.metoffice.gov.uk/", "crawl_rate": 180 }, { "title": "OpenWeatherMap", "slug": "openweathermap", "url": "http://openweathermap.org/", "crawl_rate": 360 }, { "title": "Weather Underground", "slug": "wunderground", "url": "https://www.wunderground.com/?apiref=fc30dc3cd224e19b", "crawl_rate": 720 }, { "title": "World Weather Online", "slug": "world-weather-online", "url": "http://www.worldweatheronline.com/", "crawl_rate": 360 }, { "title": "Yahoo", "slug": "yahoo", "url": "http://weather.yahoo.com/", "crawl_rate": 180 } ], "title": "Casablanca", "location_type": "City", "woeid": 1532755, "latt_long": "33.596611,-7.619340", "timezone": "Africa/Casablanca" }
通过城市名称和日期搜索
$weather->getByCityName('london', '2018/03/03');
通过坐标搜索
$weather->getByCoordinates(36.96, -122.02);
通过坐标和日期搜索
$weather->getByCoordinates(36.96, -122.02, '2018/01/01');
鸣谢
- 感谢 MetaWeather 为互联网提供开放 API。