取得目前狀況

currentConditions 端點會提供特定地點目前天氣狀況的資訊。API 會傳回以下內容:

  • 說明目前的天氣狀況,並附上相應的圖示
  • 目前氣溫
  • 體感溫度
  • 露點
  • 熱指數
  • 風寒
  • 相對濕度
  • 紫外線指數
  • 降水的機率、百分比和類型
  • 雷雨機率
  • 海平面氣壓
  • 方向、風速和陣風
  • 能見度和雲層覆蓋率
  • 過去 24 小時的歷來資料,包括溫度變化、最高和最低溫度,以及降雨量

您可以透過 APIs Explorer 提出即時要求,熟悉 API 和 API 選項:

關於目前天氣狀況要求

如要要求目前的條件,請傳送 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"
    }
  }
}

試試看!

您可以使用 APIs Explorer 建立範例要求,熟悉 API 和 API 選項。

  1. 選取頁面右側的 API 圖示 api

  2. 視需要編輯要求參數。

  3. 選取「執行」按鈕。在對話方塊中,選擇要用來提出要求的帳戶。

  4. 在「API Explorer」面板中,選取全螢幕圖示 fullscreen 即可展開「API Explorer」視窗。