Ver histórico por hora

O endpoint history.hours retorna até 24 horas de dados históricos meteorológicos por hora em um determinado local, começando pela última hora. A API retorna o seguinte:

  • Uma descrição das condições climáticas com um ícone correspondente para uma hora específica
  • Temperaturas máximas e mínimas diárias
  • Temperaturas aparentes máxima e mínima diárias ("sensação térmica")
  • Ponto de condensação
  • Índice de calor
  • Temperatura de bulbo úmido
  • Umidade relativa
  • Índice UV
  • Probabilidade, porcentagem, quantidade e tipo de precipitação
  • Probabilidade de tempestades
  • Pressão ao nível do mar
  • Resfriamento pelo vento
  • Direção, velocidade e rajada do vento
  • Espessura do gelo
  • Visibilidade e cobertura de nuvens

O APIs Explorer permite fazer solicitações em tempo real para que você se familiarize com a API e as opções dela:

Sobre as solicitações de histórico por hora

Para solicitar informações do histórico por hora, envie uma solicitação HTTP GET para:

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

Inclua as coordenadas de latitude e longitude do local nos parâmetros do URL da solicitação.

Exemplos de solicitações de histórico por hora

Por padrão, o endpoint history.hours retorna 24 horas de dados históricos do clima, começando pela última hora. É possível definir o escopo da solicitação para um período específico usando o parâmetro hours.

O exemplo a seguir solicita informações de histórico por hora das últimas três horas em Mountain View, CA:

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

Na resposta, o objeto interval indica cada hora de informações:

{
  "historyHours": [
    {
      "interval": {
        "startTime": "2025-02-12T22:00:00Z",
        "endTime": "2025-02-12T23:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 14,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      "temperature": {
        "degrees": 12.4,
        "unit": "CELSIUS"
      },
      "feelsLikeTemperature": {
        "degrees": 12.4,
        "unit": "CELSIUS"
      },
      "dewPoint": {
        "degrees": 6.1,
        "unit": "CELSIUS"
      },
      "heatIndex": {
        "degrees": 12.4,
        "unit": "CELSIUS"
      },
      "windChill": {
        "degrees": 12.4,
        "unit": "CELSIUS"
      },
      "wetBulbTemperature": {
        "degrees": 9.1,
        "unit": "CELSIUS"
      },
      "relativeHumidity": 65,
      "uvIndex": 1,
      "precipitation": {
        "probability": {
          "percent": 10,
          "type": "RAIN"
        },
        "qpf": {
          "quantity": 0,
          "unit": "MILLIMETERS"
        }
      },
      "thunderstormProbability": 0,
      "airPressure": {
        "meanSeaLevelMillibars": 1010.4
      },
      "wind": {
        "direction": {
          "degrees": 135,
          "cardinal": "SOUTHEAST"
        },
        "speed": {
          "value": 3,
          "unit": "KILOMETERS_PER_HOUR"
        },
        "gust": {
          "value": 6,
          "unit": "KILOMETERS_PER_HOUR"
        }
      },
      "visibility": {
        "distance": 16,
        "unit": "KILOMETERS"
      },
      "cloudCover": 95,
      "iceThickness": {
        "thickness": 0,
        "unit": "MILLIMETERS"
      }
    },
    {
      "interval": {
        "startTime": "2025-02-12T21:00:00Z",
        "endTime": "2025-02-12T22:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 13,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-12T20:00:00Z",
        "endTime": "2025-02-12T21:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 12,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    }
  ],
  "timeZone": {
    "id": "America/Los_Angeles"
  }
}

Especificar o número de horas a serem retornadas por página

É possível especificar o número de horas de dados a serem retornados por página usando o parâmetro de URL pageSize. O valor padrão é de 24 horas de informações de previsão por página.

As respostas com várias páginas de informações incluem um nextPageToken. Para conferir a próxima página de informações, transmita o valor nextPageToken para o parâmetro pageToken na solicitação.

O exemplo a seguir solicita oito horas de dados de previsão do tempo para Mountain View, CA, com cinco horas de dados por página:

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

A resposta, que inclui as três primeiras horas de dados, tem a seguinte forma:

{
  "historyHours": [
    {
      "interval": {
        "startTime": "2025-02-12T23:00:00Z",
        "endTime": "2025-02-13T00:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 15,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      "temperature": {
        "degrees": 11.6,
        "unit": "CELSIUS"
      },
      "feelsLikeTemperature": {
        "degrees": 11.6,
        "unit": "CELSIUS"
      },
      "dewPoint": {
        "degrees": 6.3,
        "unit": "CELSIUS"
      },
      "heatIndex": {
        "degrees": 11.6,
        "unit": "CELSIUS"
      },
      "windChill": {
        "degrees": 11.6,
        "unit": "CELSIUS"
      },
      "wetBulbTemperature": {
        "degrees": 8.8,
        "unit": "CELSIUS"
      },
      "relativeHumidity": 70,
      "uvIndex": 0,
      "precipitation": {
        "probability": {
          "percent": 10,
          "type": "RAIN"
        },
        "qpf": {
          "quantity": 0,
          "unit": "MILLIMETERS"
        }
      },
      "thunderstormProbability": 0,
      "airPressure": {
        "meanSeaLevelMillibars": 1010.07
      },
      "wind": {
        "direction": {
          "degrees": 65,
          "cardinal": "EAST_NORTHEAST"
        },
        "speed": {
          "value": 5,
          "unit": "KILOMETERS_PER_HOUR"
        },
        "gust": {
          "value": 10,
          "unit": "KILOMETERS_PER_HOUR"
        }
      },
      "visibility": {
        "distance": 16,
        "unit": "KILOMETERS"
      },
      "cloudCover": 95,
      "iceThickness": {
        "thickness": 0,
        "unit": "MILLIMETERS"
      }
    },
    {
      "interval": {
        "startTime": "2025-02-12T22:00:00Z",
        "endTime": "2025-02-12T23:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 14,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-12T21:00:00Z",
        "endTime": "2025-02-12T22:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 13,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-12T20:00:00Z",
        "endTime": "2025-02-12T21:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 12,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-12T19:00:00Z",
        "endTime": "2025-02-12T20:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 11,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    }
  ],
  "timeZone": {
    "id": "America/Los_Angeles"
  },
  "nextPageToken": "ChYKEgm8dJMYBLZCQL0xvc19BbmdlbGVz"
}

Para acessar a próxima página de dados, transmita o valor nextPageToken para o parâmetro pageToken na solicitação:

curl -X GET "https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220&location.longitude=-122.0841&hours=8&pageSize=5&pageToken=ChYKEgm8dJMYBLZCQL0xvc19BbmdlbGVz"

A resposta está no formato:

{
  "historyHours": [
    {
      "interval": {
        "startTime": "2025-02-12T18:00:00Z",
        "endTime": "2025-02-12T19:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 10,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      "temperature": {
        "degrees": 8.9,
        "unit": "CELSIUS"
      },
      "feelsLikeTemperature": {
        "degrees": 8.9,
        "unit": "CELSIUS"
      },
      "dewPoint": {
        "degrees": 5.9,
        "unit": "CELSIUS"
      },
      "heatIndex": {
        "degrees": 8.9,
        "unit": "CELSIUS"
      },
      "windChill": {
        "degrees": 8.9,
        "unit": "CELSIUS"
      },
      "wetBulbTemperature": {
        "degrees": 7.3,
        "unit": "CELSIUS"
      },
      "relativeHumidity": 82,
      "uvIndex": 1,
      "precipitation": {
        "probability": {
          "percent": 10,
          "type": "RAIN"
        },
        "qpf": {
          "quantity": 0,
          "unit": "MILLIMETERS"
        }
      },
      "thunderstormProbability": 0,
      "airPressure": {
        "meanSeaLevelMillibars": 1012.1
      },
      "wind": {
        "direction": {
          "degrees": 135,
          "cardinal": "SOUTHEAST"
        },
        "speed": {
          "value": 3,
          "unit": "KILOMETERS_PER_HOUR"
        },
        "gust": {
          "value": 8,
          "unit": "KILOMETERS_PER_HOUR"
        }
      },
      "visibility": {
        "distance": 16,
        "unit": "KILOMETERS"
      },
      "cloudCover": 100,
      "iceThickness": {
        "thickness": 0,
        "unit": "MILLIMETERS"
      }
    },
    {
      "interval": {
        "startTime": "2025-02-12T17:00:00Z",
        "endTime": "2025-02-12T18:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 9,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-12T16:00:00Z",
        "endTime": "2025-02-12T17:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 12,
        "hours": 8,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      /.../
    }
  ],
  "timeZone": {
    "id": "America/Los_Angeles"
  }
}

Confira!

O APIs Explorer permite fazer solicitações de amostra para que você se familiarize com a API e as opções dela.

  1. Selecione o ícone da API api no lado direito da página.

  2. Edite os parâmetros de solicitação, se quiser.

  3. Selecione o botão Executar. Na caixa de diálogo, escolha a conta que você quer usar para fazer a solicitação.

  4. No painel do APIs Explorer, selecione o ícone de tela cheia fullscreen para expandir a janela do APIs Explorer.