modulor/weather

从openweathermap api获取天气信息

dev-master 2016-12-13 05:47 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:55:39 UTC


README

openweathermap.org 的基本API使用示例

安装

通过 Composer

在你的项目根目录的composer.json中创建或添加以下内容

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/modulor/weather"
        }
    ],
    "require": {
        "modulor/weather": "dev-master"
    }
}

运行 composer install

示例

通过城市名称获取天气

require_once("path/to/vendor/autoload.php");

WeatherAPI\Configs::setApiKey('your_api_key');

$searchWeather = new WeatherAPI\Current\Search();

$searchWeather->setQueryParams(array(
  'q' => 'london'
));

print_r($searchWeather->execute());

通过地理坐标获取天气

require_once("path/to/vendor/autoload.php");

WeatherAPI\Configs::setApiKey('your_api_key');

$searchWeather = new WeatherAPI\Current\Search();

$searchWeather->setQueryParams(array(
  'lat' => '-22.0622478',
  'lon' => '-44.0444834'
));

print_r($searchWeather->execute());