获取当前天气状况

currentConditions 端点提供有关特定地点当前天气状况的信息。API 会返回以下内容:

  • 当前天气状况的说明,以及相应的图标
  • 当前温度
  • 体感温度
  • 露点
  • 热指数
  • 风寒效应
  • 相对湿度传感器
  • 紫外线指数
  • 降水概率、百分比和类型
  • 雷暴概率
  • 海平面气压
  • 、风速和阵风
  • 能见度和云层覆盖率
  • 过去 24 小时的历史数据,包括温度变化、最高温度、最低温度和降水量

实时天气请求简介

如需请求当前状况,请向以下网址发送 HTTP GET 请求:

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

在请求网址参数中添加相应位置的纬度和经度坐标。

当前状况请求示例

以下示例请求加利福尼亚州山景城的当前状况信息:

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

响应格式如下:

{
  "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"
    }
  }
}

指定单位制

默认情况下,Weather API 会以公制单位返回数据。如需使用英制单位请求天气数据,请在请求中指定 unitsSystem 参数。

以下示例请求加利福尼亚州山景城以英制单位显示的天气数据:

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

响应格式如下:

{
  "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"
    }
  }
}