Receba a previsão de hora em hora

O endpoint forecast.hours retorna até 240 horas de informações de previsão para um local específico, a partir do horário atual. A API retorna o seguinte:

  • Uma descrição das condições climáticas atuais com um ícone correspondente
  • Temperatura atual
  • Temperatura aparente ("sensação térmica")
  • Ponto de condensação
  • Índice de calor
  • Resfriamento pelo vento
  • Temperatura de bulbo úmido
  • Umidade relativa
  • Índice UV
  • Probabilidade, porcentagem e tipo de precipitação
  • Probabilidade de tempestades
  • Pressão ao nível do mar
  • Direção, velocidade e rajada do vento
  • 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 previsão de hora em hora

Para solicitar informações de previsão por hora, envie uma solicitação HTTP GET para:

https://weather.googleapis.com/v1/forecast/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 previsão de hora em hora

Por padrão, o endpoint forecast.hours retorna 240 horas de dados, começando pela hora atual. É possível limitar sua solicitação a um período específico usando o parâmetro hours.

O exemplo a seguir solicita informações de previsão por hora para as próximas três horas em Mountain View, CA:

curl -X GET "https://weather.googleapis.com/v1/forecast/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:

{
  "forecastHours": [
    {
      "interval": {
        "startTime": "2025-02-05T23:00:00Z",
        "endTime": "2025-02-06T00:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 5,
        "hours": 15,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny",
        "description": {
          "text": "Sunny",
          "languageCode": "en"
        },
        "type": "CLEAR"
      },
      "temperature": {
        "degrees": 12.7,
        "unit": "CELSIUS"
      },
      "feelsLikeTemperature": {
        "degrees": 12,
        "unit": "CELSIUS"
      },
      "dewPoint": {
        "degrees": 2.7,
        "unit": "CELSIUS"
      },
      "heatIndex": {
        "degrees": 12.7,
        "unit": "CELSIUS"
      },
      "windChill": {
        "degrees": 12,
        "unit": "CELSIUS"
      },
      "wetBulbTemperature": {
        "degrees": 7.7,
        "unit": "CELSIUS"
      },
      "relativeHumidity": 51,
      "uvIndex": 1,
      "precipitation": {
        "probability": {
          "percent": 0,
          "type": "RAIN"
        },
        "qpf": {
          "quantity": 0,
          "unit": "MILLIMETERS"
        }
      },
      "thunderstormProbability": 0,
      "airPressure": {
        "meanSeaLevelMillibars": 1019.13
      },
      "wind": {
        "direction": {
          "degrees": 335,
          "cardinal": "NORTH_NORTHWEST"
        },
        "speed": {
          "value": 10,
          "unit": "KILOMETERS_PER_HOUR"
        },
        "gust": {
          "value": 19,
          "unit": "KILOMETERS_PER_HOUR"
        }
      },
      "visibility": {
        "distance": 16,
        "unit": "KILOMETERS"
      },
      "cloudCover": 0,
      "iceThickness": {
        "thickness": 0,
        "unit": "MILLIMETERS"
      }
    },
    {
      "interval": {
        "startTime": "2025-02-06T00:00:00Z",
        "endTime": "2025-02-06T01:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 5,
        "hours": 16,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny",
        "description": {
          "text": "Sunny",
          "languageCode": "en"
        },
        "type": "CLEAR"
      },
      "temperature": {
        "degrees": 12.5,
        "unit": "CELSIUS"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-06T01:00:00Z",
        "endTime": "2025-02-06T02:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 5,
        "hours": 17,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny",
        "description": {
          "text": "Sunny",
          "languageCode": "en"
        },
        "type": "CLEAR"
      },
      "temperature": {
        "degrees": 11.4,
        "unit": "CELSIUS"
      },
      /.../
    }
  ],
  "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 25 horas de dados de previsão do tempo para Mountain View, CA, com três horas de dados por página:

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

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

{
  "forecastHours": [
    {
      "interval": {
        "startTime": "2025-02-06T23:00:00Z",
        "endTime": "2025-02-07T00:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 6,
        "hours": 15,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/showers",
        "description": {
          "text": "Rain showers",
          "languageCode": "en"
        },
        "type": "RAIN_SHOWERS"
      },
      "temperature": {
        "degrees": 14.6,
        "unit": "CELSIUS"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-07T00:00:00Z",
        "endTime": "2025-02-07T01:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 6,
        "hours": 16,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/drizzle",
        "description": {
          "text": "Light rain",
          "languageCode": "en"
        },
        "type": "LIGHT_RAIN"
      },
      "temperature": {
        "degrees": 14.4,
        "unit": "CELSIUS"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-07T01:00:00Z",
        "endTime": "2025-02-07T02:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 6,
        "hours": 17,
        "utcOffset": "-28800s"
      },
      "isDaytime": true,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      "temperature": {
        "degrees": 14.4,
        "unit": "CELSIUS"
      },
      /.../
    }
  ],
  "timeZone": {
    "id": "America/Los_Angeles"
  },
  "nextPageToken": "ChYKEgm8dJMYBLZCQBH-ZffkYYVewBAZEAMYAyIMCLKClb0GEJeO18kDKhNBbWVyaWNhL0xvc19BbmdlbGVz"
}

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/forecast/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220&location.longitude=-122.0841&hours=25&pageSize=3&pageToken=ChYKEgm8dJMYBLZCQBH-ZffkYYVewBAZEAMYAyIMCLKClb0GEJeO18kDKhNBbWVyaWNhL0xvc19BbmdlbGVz"

A resposta está no formato:

{
  "forecastHours": [
    {
      "interval": {
        "startTime": "2025-02-07T02:00:00Z",
        "endTime": "2025-02-07T03:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 6,
        "hours": 18,
        "utcOffset": "-28800s"
      },
      "isDaytime": false,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy",
        "description": {
          "text": "Cloudy",
          "languageCode": "en"
        },
        "type": "CLOUDY"
      },
      "temperature": {
        "degrees": 14.3,
        "unit": "CELSIUS"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-07T03:00:00Z",
        "endTime": "2025-02-07T04:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 6,
        "hours": 19,
        "utcOffset": "-28800s"
      },
      "isDaytime": false,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/showers",
        "description": {
          "text": "Rain showers",
          "languageCode": "en"
        },
        "type": "RAIN_SHOWERS"
      },
      "temperature": {
        "degrees": 14.2,
        "unit": "CELSIUS"
      },
      /.../
    },
    {
      "interval": {
        "startTime": "2025-02-07T04:00:00Z",
        "endTime": "2025-02-07T05:00:00Z"
      },
      "displayDateTime": {
        "year": 2025,
        "month": 2,
        "day": 6,
        "hours": 20,
        "utcOffset": "-28800s"
      },
      "isDaytime": false,
      "weatherCondition": {
        "iconBaseUri": "https://maps.gstatic.com/weather/v1/showers",
        "description": {
          "text": "Rain showers",
          "languageCode": "en"
        },
        "type": "RAIN_SHOWERS"
      },
      "temperature": {
        "degrees": 14.1,
        "unit": "CELSIUS"
      },
      /.../
    }
  ],
  "timeZone": {
    "id": "America/Los_Angeles"
  },
  "nextPageToken": "ChYKEgm8dJMYBLZCQBH-ZffkYYVewBAZEAYYBiILCPeDlb0GEICs5TMqE0FtZXJpY2EvTG9zX0FuZ2VsZXM="
}

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.