Dapatkan perkiraan per jam

Endpoint forecast.hours menampilkan informasi perkiraan hingga 240 jam untuk lokasi tertentu, dimulai dari jam saat ini. API menampilkan berikut ini:

  • Deskripsi kondisi cuaca saat ini dengan ikon yang sesuai
  • Suhu saat ini
  • Suhu nyata ("terasa seperti")
  • Titik embun
  • Indeks panas
  • Angin dingin
  • Suhu bohlam basah
  • Kelembapan relatif
  • Indeks UV
  • Probabilitas, persentase, dan jenis presipitasi
  • Kemungkinan badai petir
  • Tekanan permukaan laut
  • Arah angin, kecepatan, dan embusan
  • Visibilitas dan tutupan awan

APIs Explorer memungkinkan Anda membuat permintaan langsung sehingga Anda dapat memahami API dan opsi API:

Tentang permintaan prakiraan cuaca per jam

Untuk meminta informasi perkiraan per jam, kirim permintaan HTTP GET ke:

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

Sertakan koordinat lintang dan bujur lokasi dalam parameter URL permintaan .

Contoh permintaan prakiraan cuaca per jam

Secara default, endpoint forecast.hours menampilkan data selama 240 jam, dimulai dari jam saat ini. Anda dapat mencakup permintaan ke jangka waktu tertentu menggunakan parameter hours.

Contoh berikut meminta informasi perkiraan per jam untuk tiga jam ke depan untuk 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"

Dalam respons, objek interval menunjukkan setiap jam informasi:

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

Tentukan jumlah jam yang akan ditampilkan per halaman

Anda dapat menentukan jumlah jam data yang akan ditampilkan per halaman menggunakan parameter URL pageSize. Nilai defaultnya adalah 24 jam informasi perkiraan per halaman.

Respons dengan beberapa halaman informasi menyertakan nextPageToken. Untuk melihat halaman informasi berikutnya, teruskan nilai nextPageToken ke parameter pageToken dalam permintaan Anda.

Contoh berikut meminta data perkiraan cuaca selama 25 jam untuk Mountain View, CA, dengan tiga jam data per halaman:

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"

Respons, yang mencakup tiga jam pertama data, berbentuk:

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

Untuk mengakses halaman data berikutnya, teruskan nilai nextPageToken ke dalam parameter pageToken dalam permintaan Anda:

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"

Responsnya dalam bentuk:

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

Cobalah!

APIs Explorer memungkinkan Anda membuat contoh permintaan sehingga Anda dapat memahami API dan opsi API.

  1. Pilih ikon API api di sisi kanan halaman.

  2. Edit parameter permintaan secara opsional.

  3. Pilih tombol Execute. Dalam dialog, pilih akun yang ingin Anda gunakan untuk membuat permintaan.

  4. Di panel APIs Explorer, pilih ikon layar penuh fullscreen untuk meluaskan jendela APIs Explorer.