Nhận thông tin về điều kiện hiện tại

Điểm cuối currentConditions cung cấp thông tin về tình trạng thời tiết hiện tại ở một vị trí cụ thể. API này trả về những thông tin sau:

  • Nội dung mô tả về tình trạng thời tiết hiện tại kèm theo một biểu tượng tương ứng
  • Nhiệt độ hiện tại
  • Nhiệt độ cảm nhận ("cảm thấy như")
  • Điểm sương
  • Chỉ số nhiệt
  • Gió lạnh
  • Độ ẩm tương đối
  • Chỉ số UV
  • Xác suất, tỷ lệ phần trăm và loại mưa
  • Xác suất có bão kèm theo sấm sét
  • Áp suất mực nước biển
  • Hướng gió , tốc độ gió và gió giật
  • Tầm nhìn và độ che phủ của mây
  • Dữ liệu lịch sử trong 24 giờ qua, bao gồm cả sự thay đổi nhiệt độ, nhiệt độ tối đa và tối thiểu, cũng như lượng mưa

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

Giới thiệu về các yêu cầu về tình trạng hiện tại

Để yêu cầu thông tin về tình trạng hiện tại, hãy gửi yêu cầu GET HTTP đến:

https://weather.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE

Đưa toạ độ vĩ độ và kinh độ của vị trí vào các tham số URL yêu cầu.

Ví dụ về yêu cầu về tình trạng hiện tại

Ví dụ sau đây yêu cầu thông tin về tình trạng hiện tại của Mountain View, CA:

curl -X GET "https://weather.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY&location.latitude=37.4220&location.longitude=-122.0841"

Phản hồi có dạng:

{
  "currentTime": "2025-01-28T22:04:12.025273178Z",
  "timeZone": {
    "id": "America/Los_Angeles"
  },
  "isDaytime": true,
  "weatherCondition": {
    "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny",
    "description": {
      "text": "Sunny",
      "languageCode": "en"
    },
    "type": "CLEAR"
  },
  "temperature": {
    "degrees": 13.7,
    "unit": "CELSIUS"
  },
  "feelsLikeTemperature": {
    "degrees": 13.1,
    "unit": "CELSIUS"
  },
  "dewPoint": {
    "degrees": 1.1,
    "unit": "CELSIUS"
  },
  "heatIndex": {
    "degrees": 13.7,
    "unit": "CELSIUS"
  },
  "windChill": {
    "degrees": 13.1,
    "unit": "CELSIUS"
  },
  "relativeHumidity": 42,
  "uvIndex": 1,
  "precipitation": {
    "probability": {
      "percent": 0,
      "type": "RAIN"
    },
    "qpf": {
      "quantity": 0,
      "unit": "MILLIMETERS"
    }
  },
  "thunderstormProbability": 0,
  "airPressure": {
    "meanSeaLevelMillibars": 1019.16
  },
  "wind": {
    "direction": {
      "degrees": 335,
      "cardinal": "NORTH_NORTHWEST"
    },
    "speed": {
      "value": 8,
      "unit": "KILOMETERS_PER_HOUR"
    },
    "gust": {
      "value": 18,
      "unit": "KILOMETERS_PER_HOUR"
    }
  },
  "visibility": {
    "distance": 16,
    "unit": "KILOMETERS"
  },
  "cloudCover": 0,
  "currentConditionsHistory": {
    "temperatureChange": {
      "degrees": -0.6,
      "unit": "CELSIUS"
    },
    "maxTemperature": {
      "degrees": 14.3,
      "unit": "CELSIUS"
    },
    "minTemperature": {
      "degrees": 3.7,
      "unit": "CELSIUS"
    },
    "qpf": {
      "quantity": 0,
      "unit": "MILLIMETERS"
    }
  }
}

Chỉ định hệ thống đơn vị

Theo mặc định, Weather API trả về dữ liệu theo hệ thống đo lường. Để yêu cầu dữ liệu thời tiết bằng hệ thống đo lường Anh, hãy chỉ định tham số unitsSystem trong yêu cầu.

Ví dụ sau đây yêu cầu dữ liệu thời tiết cho Mountain View, CA theo đơn vị đo lường Anh:

curl -X GET "https://weather.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY&location.latitude=37.4220&location.longitude=-122.0841&unitsSystem=IMPERIAL"

Phản hồi có dạng:

{
  "currentTime": "2025-01-28T22:13:56.723468335Z",
  "timeZone": {
    "id": "America/Los_Angeles"
  },
  "isDaytime": true,
  "weatherCondition": {
    "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny",
    "description": {
      "text": "Sunny",
      "languageCode": "en"
    },
    "type": "CLEAR"
  },
  "temperature": {
    "degrees": 56.6,
    "unit": "FAHRENHEIT"
  },
  "feelsLikeTemperature": {
    "degrees": 55.7,
    "unit": "FAHRENHEIT"
  },
  "dewPoint": {
    "degrees": 33.9,
    "unit": "FAHRENHEIT"
  },
  "heatIndex": {
    "degrees": 56.6,
    "unit": "FAHRENHEIT"
  },
  "windChill": {
    "degrees": 55.7,
    "unit": "FAHRENHEIT"
  },
  "relativeHumidity": 42,
  "uvIndex": 1,
  "precipitation": {
    "probability": {
      "percent": 0,
      "type": "RAIN"
    },
    "qpf": {
      "quantity": 0,
      "unit": "INCHES"
    }
  },
  "thunderstormProbability": 0,
  "airPressure": {
    "meanSeaLevelMillibars": 1019.12
  },
  "wind": {
    "direction": {
      "degrees": 335,
      "cardinal": "NORTH_NORTHWEST"
    },
    "speed": {
      "value": 5,
      "unit": "MILES_PER_HOUR"
    },
    "gust": {
      "value": 11,
      "unit": "MILES_PER_HOUR"
    }
  },
  "visibility": {
    "distance": 10,
    "unit": "MILES"
  },
  "cloudCover": 0,
  "currentConditionsHistory": {
    "temperatureChange": {
      "degrees": -1.2,
      "unit": "FAHRENHEIT"
    },
    "maxTemperature": {
      "degrees": 57.8,
      "unit": "FAHRENHEIT"
    },
    "minTemperature": {
      "degrees": 38.6,
      "unit": "FAHRENHEIT"
    },
    "qpf": {
      "quantity": 0,
      "unit": "INCHES"
    }
  }
}

Hãy làm thử!

APIs Explorer cho phép bạn đưa ra các yêu cầu mẫu để 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.

  3. Chọn nút Execute (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.