Skip to content

Commit 714fe89

Browse files
committed
Chinese Translation
1 parent 5e3afe7 commit 714fe89

File tree

2 files changed

+261
-0
lines changed

2 files changed

+261
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: 空氣污染 API
3+
sidebar_label: '空氣污染'
4+
---
5+
6+
此 API 允許您檢索當前、預測和歷史的紫外線指數(UV 指數)。
7+
8+
> 對應的 OpenWeatherMap 文件:
9+
>
10+
> - [一氧化碳 (CO)](https://openweathermap.org/api/pollution/co)
11+
> - [臭氧 (O3)](https://openweathermap.org/api/pollution/o3)
12+
> - [二氧化氮 (NO2)](https://openweathermap.org/api/pollution/no2)
13+
> - [二氧化硫 (SO2)](https://openweathermap.org/api/pollution/so2)
14+
15+
## 用法
16+
17+
- `$type`:可以是 `"O3"``"NO2"``"SO2"``"CO"` 其中之一。
18+
- `$lat` / `$lng`:緯度和經度必須以字符串形式提供,因為小數點後的位數決定了搜索半徑。指定更多位數會導致更精確的結果,但位數過多可能導致無法獲取結果。
19+
- `$date`:要檢索數據的日期。`"current"` 請求最新可用的信息。您也可以以 ISO 8601 格式指定日期。更多信息請參見 [OpenWeatherMap 文件](https://openweathermap.org/api/pollution/co)
20+
21+
```php
22+
// $type =
23+
$co = $owm->getAirPollution($type, $lat, $lng, $date = "current");
24+
```
25+
26+
返回值取決於 `$type`,在後續部分進行討論。
27+
28+
## 一氧化碳 (CO)
29+
30+
```php
31+
$co = $owm->getAirPollution("CO", "52", "13");
32+
if ($co === null) {
33+
// 無可用數據
34+
} else {
35+
foreach ($co->values as $data) {
36+
echo $data["value"];
37+
echo $data["value"]->getPrecision();
38+
echo $data["pressure"];
39+
}
40+
}
41+
```
42+
43+
## 臭氧 (O3)
44+
45+
```php
46+
$o3 = $owm->getAirPollution("O3", "52", "13");
47+
if ($o3 === null) {
48+
// 無可用數據
49+
} else {
50+
echo $o3->value;
51+
}
52+
```
53+
54+
## 二氧化氮 (NO2)
55+
56+
```php
57+
$no2 = $owm->getAirPollution("NO2", "52", "13");
58+
if ($no2 === null) {
59+
// 無可用數據
60+
} else {
61+
echo $no2->value;
62+
echo $no2->valueStratosphere;
63+
echo $no2->valueTroposphere;
64+
}
65+
```
66+
67+
## 二氧化硫 (SO2)
68+
69+
```php
70+
$so2 = $owm->getAirPollution("SO2", "52", "13");
71+
if ($so2 === null) {
72+
// 無可用數據
73+
} else {
74+
foreach ($so2->values as $data) {
75+
echo $data["value"];
76+
echo $data["value"]->getPrecision();
77+
echo $data["pressure"];
78+
}
79+
}
80+
```
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
title: 當前天氣 API
3+
sidebar_label: '當前天氣'
4+
---
5+
6+
此 API 允許您檢索當前的天氣數據。
7+
8+
> [對應的 OpenWeatherMap 文件](https://openweathermap.org/current)
9+
10+
`$owm->getWeather()` 函式接受以下參數:
11+
12+
| 名稱 | 類型 | 預設值 | 描述 |
13+
|------|------|---------|-------------|
14+
| `$query` | `mixed` | -- | 請參見下文 |
15+
| `$units` | `"imperial"`|`"metric"` | `"imperial"` | 使用的單位 |
16+
| `$lang` | `string` | `en` | 語言之一,請參見 [官方文件底部](https://openweathermap.org/current#multi) |
17+
18+
## `$query` 參數
19+
20+
第一個參數確定要獲取天氣數據的位置。有多種函式可用:
21+
22+
### 根據城市名稱
23+
24+
指定國家是可選的。
25+
26+
```php
27+
$weather = $owm->getWeather('Berlin,DE', $units, $lang);
28+
```
29+
30+
### 根據城市 ID
31+
32+
單個城市 ID:
33+
```php
34+
$weather = $owm->getWeather(2172797, $units, $lang);
35+
```
36+
37+
多個城市 ID:
38+
```php
39+
// 警告:這使用了一個不同的函式 (getWeatherGroup)
40+
// 與其他查詢格式 (getWeather) 不同!
41+
$weathers = $owm->getWeatherGroup([2172797, 2172798], $units, $lang);
42+
foreach ($weathers as $weather) {
43+
// 處理
44+
}
45+
```
46+
47+
### 根據郵政編碼
48+
49+
指定國家是可選的。
50+
51+
```php
52+
// 印度,海得拉巴
53+
$weather = $owm->getWeather('zip:500001,IN', $units, $lang);
54+
```
55+
56+
### 根據座標
57+
58+
```php
59+
$weather = $owm->getWeather(['lat' => 77.73038, 'lon' => 41.89604],
60+
$units, $lang);
61+
```
62+
63+
## `$weather` 對象
64+
65+
返回的對象是一個 `Cmfcmf\OpenWeatherMap\CurrentWeather` 實例。它提供以下數據:
66+
67+
| 名稱 | 類型 | 描述 |
68+
|------|------|-------------|
69+
| `lastUpdate` | `\DateTimeInterface` | 數據的最後更新時間 |
70+
| `temperature->now` | `Unit` | 注意:這應命名為 `temperature->avg`,僅為向後兼容而命名為 `temperature->now`!返回給定位置的當前平均溫度(例如,一個大城市可能有多個溫度測量站) |
71+
| `temperature->min` | `Unit` | 給定位置的當前最低溫度 |
72+
| `temperature->max` | `Unit` | 給定位置的當前最高溫度 |
73+
| `pressure` | `Unit` | 氣壓 |
74+
| `humidity` | `Unit` | 濕度 |
75+
| `sun->rise` | `\DateTimeInterface` | 日出時間 |
76+
| `sun->set` | `\DateTimeInterface` | 日落時間 |
77+
| `wind->speed` | `Unit` | 風速 |
78+
| `wind->direction` | `Unit` | 風向 |
79+
| `clouds` | `Unit` | 雲量百分比 |
80+
| `precipitation` | `Unit` | 最近的降水 |
81+
| `weather->id` | `int` | 當前天氣現象 ID |
82+
| `weather->description` | `string` | 當前天氣描述 |
83+
| `weather->icon` | `string` | 當前天氣圖標名稱。使用 `weather->getIconUrl()` 獲取 OpenWeatherMap 圖標的 URL |
84+
| `city->id` | `int` | 內部城市 ID |
85+
| `city->name` | `string` | 城市名稱 |
86+
| `city->country` | `string` | 城市國家代碼 |
87+
| `city->timezone` | `\DateTimeZone`|`null` | 城市時區 |
88+
| `city->lon` | `float` | 城市經度 |
89+
| `city->lat` | `float` | 城市緯度 |
90+
91+
## 獲取原始數據
92+
93+
### HTML
94+
95+
您還可以請求以 HTML 頁面形式的數據:
96+
97+
```php
98+
$html = $owm->getRawWeatherData('Berlin', $units, $lang, null, 'html');
99+
```
100+
101+
結果:
102+
103+
```html
104+
<!DOCTYPE html>
105+
<html lang="en">
106+
<head>
107+
<meta charset="utf-8">
108+
<meta name="keywords" content="weather, world, openweathermap, weather, layer" />
109+
<meta name="description" content="A layer with current weather conditions in cities for world wide" />
110+
<meta name="domain" content="openweathermap.org" />
111+
<meta http-equiv="pragma" content="no-cache" />
112+
<meta http-equiv="Expires" content="-1" />
113+
</head>
114+
<body>
115+
<div style="font-size: medium; font-weight: bold; margin-bottom: 0px;">Berlin</div>
116+
<div style="float: left; width: 130px;">
117+
<div style="display: block; clear: left;">
118+
<div style="float: left;" title="Titel">
119+
<img height="45" width="45" style="border: medium none; width: 45px; height: 45px; background: url(&quot;http://openweathermap.org/img/w/04d.png&quot;) repeat scroll 0% 0% transparent;" alt="title" src="http://openweathermap.org/images/transparent.png"/>
120+
</div>
121+
<div style="float: left;">
122+
<div style="display: block; clear: left; font-size: medium; font-weight: bold; padding: 0pt 3pt;" title="Current Temperature">12.73°C</div>
123+
<div style="display: block; width: 85px; overflow: visible;"></div>
124+
</div>
125+
</div>
126+
<div style="display: block; clear: left; font-size: small;">雲量:89%</div>
127+
<div style="display: block; clear: left; color: gray; font-size: x-small;" >濕度:62%</div>
128+
<div style="display: block; clear: left; color: gray; font-size: x-small;" >風速:6.2 m/s</div>
129+
<div style="display: block; clear: left; color: gray; font-size: x-small;" >氣壓:1014hpa</div>
130+
</div>
131+
<div style="display: block; clear: left; color: gray; font-size: x-small;">
132+
<a href="http://openweathermap.org/city/2950159?utm_source=openweathermap&utm_medium=widget&utm_campaign=html_old" target="_blank">更多..</a>
133+
</div>
134+
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
135+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
136+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
137+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-31601618-9', 'auto');ga('send', 'pageview');</script>
138+
</body>
139+
</html>
140+
```
141+
142+
### JSON
143+
144+
```php
145+
$json = $owm->getRawWeatherData('Berlin', 'metric', 'de', null, 'json');
146+
```
147+
結果:
148+
149+
```json
150+
{
151+
"coord":{"lon":13.41,"lat":52.52},
152+
"weather":[{"id":804,"main":"Clouds","description":"Bedeckt","icon":"04d"}],
153+
"base":"stations",
154+
"main":{"temp":12.73,"feels_like":7.4,"temp_min":11.67,
155+
"temp_max":13.89,"pressure":1014,"humidity":62},
156+
"visibility":10000,
157+
"wind":{"speed":6.2,"deg":200},
158+
"clouds":{"all":89},
159+
"dt":1579089181,
160+
"sys":{"type":1,"id":1275,"country":"DE","sunrise":1579072219,"sunset":1579101619},
161+
"timezone":3600,
162+
"id":2950159,
163+
"name":"Berlin",
164+
"cod":200
165+
}
166+
```
167+
168+
### XML
169+
170+
```php
171+
$xml = $owm->getRawWeatherData('Berlin', 'metric', 'de', null, 'xml');
172+
```
173+
174+
結果:
175+
176+
```xml
177+
<?xml version="1.0" encoding="UTF-8"?>
178+
<current><city id="2950159" name="Berlin"><coord lon="13.41" lat="52.52"></coord><country>DE</country><timezone>3600</timezone><sun rise="2020-01-15T07:10:19
179+
180+
" set="2020-01-15T15:20:19"></sun></city><temperature value="12.73" min="11.67" max="13.89" unit="celsius"></temperature><feels_like value="7.4" unit="celsius"></feels_like><humidity value="62" unit="%"></humidity><pressure value="1014" unit="hPa"></pressure><wind><speed value="6.2" unit="m/s" name="Moderate breeze"></speed><gusts></gusts><direction value="200" code="SSW" name="South-southwest"></direction></wind><clouds value="89" name="Bedeckt"></clouds><visibility value="10000"></visibility><precipitation mode="no"></precipitation><weather number="804" value="Bedeckt" icon="04d"></weather><lastupdate value="2020-01-15T11:53:01"></lastupdate></current>
181+
```

0 commit comments

Comments
 (0)