Tình trạng hiện tại

Điểm cuối currentConditions cung cấp thông tin về chất lượng không khí theo giờ hiện tại. Bạn có thể kiểm soát những chỉ số AQI và thông tin liên quan được trả về (chẳng hạn như mức độ nồng độ chất gây ô nhiễm và các khuyến nghị về sức khoẻ).

Bạn có thể yêu cầu chất lượng không khí theo giờ hiện tại bằng cách sử dụng điểm cuối currentConditions bằng cách gửi yêu cầu HTTP POST đến:

https://airquality.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY

Thêm các lựa chọn yêu cầu vào nội dung yêu cầu JSON. Phần nội dung yêu cầu chứa vị trí mà bạn muốn nhận thông tin về tình trạng hiện tại của chất lượng không khí và nhiều lựa chọn để kiểm soát thông tin về chất lượng không khí cần đưa vào phản hồi.

API Explorer cho phép bạn đưa ra các yêu cầu trực tiếp để có thể làm quen với API và các lựa chọn API:

Ví dụ về yêu cầu cơ bản

Nội dung yêu cầu cơ bản

Đoạn mã sau đây cho biết cách tạo một nội dung yêu cầu cơ bản cho yêu cầu currentConditions. Trong ví dụ này, bạn chỉ đặt vị trí.

curl -X POST -d '{
  "location": {
    "latitude": 37.419734,
    "longitude": -122.0827784
  }
}' \
-H 'Content-Type: application/json' \
'https://airquality.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY'

Phản hồi yêu cầu cơ bản

Lệnh gọi ở trên sẽ tạo ra phản hồi JSON sau đây. Để biết thêm thông tin về dữ liệu phản hồi, hãy xem phần Dữ liệu phản hồi.

{
  "dateTime": "2023-10-26T18:00:00Z",
  "regionCode": "us",
  "indexes": [
    {
      "code": "uaqi",
      "displayName": "Universal AQI",
      "aqi": 52,
      "aqiDisplay": "52",
      "color": {
        "red": 0.9490196,
        "green": 0.98039216,
        "blue": 0.019607844
      },
      "category": "Moderate air quality",
      "dominantPollutant": "no2"
    }
  ]
}

Ví dụ về yêu cầu có nhiều tham số

Yêu cầu nhiều tham số

Đoạn mã sau đây cho biết cách tạo một nội dung yêu cầu cho yêu cầu currentConditions. Trong ví dụ này, ngoài vị trí, một số phép tính bổ sung và ngôn ngữ phản hồi cũng được chỉ định.

curl -X POST -d '{
  "universalAqi": true,
  "location": {
    "latitude": 37.419734,
    "longitude": -122.0827784
  },
  "extraComputations": [
    "HEALTH_RECOMMENDATIONS",
    "DOMINANT_POLLUTANT_CONCENTRATION",
    "POLLUTANT_CONCENTRATION",
    "LOCAL_AQI",
    "POLLUTANT_ADDITIONAL_INFO"
  ],
  "languageCode": "en"
}' \
-H 'Content-Type: application/json' \
'https://airquality.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY'

Phản hồi nhiều tham số

Lệnh gọi ở trên sẽ tạo ra phản hồi JSON sau đây. Để biết thêm thông tin về dữ liệu phản hồi, hãy xem phần Dữ liệu phản hồi.

{
    "dateTime": "2023-06-15T10:00:00Z",
    "regionCode": "us",
    "indexes": [
        {
            "code": "uaqi",
            "displayName": "Universal AQI",
            "aqi": 89,
            "aqiDisplay": "89",
            "color": {
                "red": 48,
                "green": 175,
                "blue": 55,
                "alpha": 255
            },
            "category": "Excellent air quality",
            "dominantPollutant": "o3"
        },
        {
            "code": "usa_epa",
            "displayName": "AQI (US)",
            "aqi": 41,
            "aqiDisplay": "41",
            "color": {
                "green": 228,
                "alpha": 255
            },
            "category": "Good air quality",
            "dominantPollutant": "pm25"
        }
    ],
    "pollutants": [
        {
            "code": "co",
            "displayName": "CO",
            "fullName": "Carbon monoxide",
            "concentration": {
                "value": 334.24,
                "units": "PARTS_PER_BILLION"
            },
            "additionalInfo": {
                "sources": "Typically originates from incomplete combustion...",
                "effects": "When inhaled, carbon monoxide can prevent the blood from..."
            }
        },
        {
            "code": "no2",
            "displayName": "NO2",
            "fullName": "Nitrogen dioxide",
            "concentration": {
                "value": 13.12,
                "units": "PARTS_PER_BILLION"
            },
            "additionalInfo": {
                "sources": "Main sources are fuel burning processes, such as...",
                "effects": "Exposure may cause increased bronchial reactivity..."
            }
        },
        {
            "code": "o3",
            "displayName": "O3",
            "fullName": "Ozone",
            "concentration": {
                "value": 13.88,
                "units": "PARTS_PER_BILLION"
            },
            "additionalInfo": {
                "sources": "Ozone is created in a chemical reaction between atmospheric oxygen...",
                "effects": "Ozone can irritate the airways and cause coughing, a burning..."
            }
        },
        {
            "code": "pm10",
            "displayName": "PM10",
            "fullName": "Inhalable particulate matter (<10µm)",
            "concentration": {
                "value": 5.07,
                "units": "MICROGRAMS_PER_CUBIC_METER"
            },
            "additionalInfo": {
                "sources": "Main sources are combustion processes (e.g. indoor heating, wildfires)...",
                "effects": "Inhalable particles can penetrate into the lungs. Short term exposure..."
            }
        },
        {
            "code": "pm25",
            "displayName": "PM2.5",
            "fullName": "Fine particulate matter (<2.5µm)",
            "concentration": {
                "value": 2.83,
                "units": "MICROGRAMS_PER_CUBIC_METER"
            },
            "additionalInfo": {
                "sources": "Main sources are combustion processes (e.g. power plants, indoor heating...",
                "effects": "Fine particles can penetrate into the lungs and bloodstream. Short term..."
            }
        },
        {
            "code": "so2",
            "displayName": "SO2",
            "fullName": "Sulfur dioxide",
            "concentration": {
                "value": 0.02,
                "units": "PARTS_PER_BILLION"
            },
            "additionalInfo": {
                "sources": "Main sources are burning processes of sulfur-containing fuel in industry...",
                "effects": "Exposure causes irritation of the respiratory tract, coughing and generates..."
            }
        }
    ],
    "healthRecommendations": {
        "generalPopulation": "With this level of air quality, you have no limitations. Enjoy the outdoors!",
        "elderly": "If you start to feel respiratory discomfort such as coughing or breathing difficulties...",
        "lungDiseasePopulation": "...",
        "heartDiseasePopulation": "...",
        "athletes": "...",
        "pregnantWomen": "...",
        "children": "..."
    }
}

Hãy dùng thử!

Trình khám phá API cho phép bạn đưa ra các yêu cầu mẫu để có thể làm quen với API và các lựa chọn API.

  1. Chọn biểu tượng API api ở bên phải trang.

  2. Bạn có thể chỉnh sửa các tham số yêu cầu (không bắt buộc).

  3. Chọn nút Thực thi. Trong hộp thoại, hãy chọn tài khoản mà bạn muốn dùng để đưa ra yêu cầu.

  4. Trong bảng điều khiển APIs Explorer, hãy chọn biểu tượng toàn màn hình fullscreen để mở rộng cửa sổ APIs Explorer.