קבלת תחזית לפי שעה

נקודת הקצה forecast.hours מחזירה עד 240 שעות של נתוני תחזית למיקום ספציפי, החל מהשעה הנוכחית. ה-API מחזיר את הפרטים הבאים:

  • תיאור של תנאי מזג האוויר הנוכחיים עם סמל תואם
  • הטמפרטורה הנוכחית
  • הטמפרטורה המדומה ('הטמפרטורה המורגשת')
  • נקודת הטל
  • מדד חום
  • צינת רוח
  • טמפרטורת התרמומטר הרטוב
  • לחות יחסית
  • מדד UV
  • הסיכוי, האחוז והסוג של המשקעים
  • סבירות לסופות רעמים
  • לחץ בגובה פני הים
  • כיוון, מהירות ומשבים של הרוח
  • ראות ועוצמת עננות

ב-APIs Explorer אפשר לשלוח בקשות בזמן אמת כדי להתנסות ב-API ובאפשרויות שלו:

מידע על בקשות לתחזיות שעתיות

כדי לבקש מידע על תחזית לשעה, שולחים בקשת HTTP GET אל:

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

צריך לכלול את קואורדינטות קו האורך וקו הרוחב של המיקום בפרמטרים של כתובת ה-URL של הבקשה.

דוגמאות לבקשות של תחזיות שעתיות

כברירת מחדל, נקודת הקצה forecast.hours מחזירה נתונים של 240 שעות, החל מהשעה הנוכחית. אפשר להגדיר את היקף הבקשה לתקופה ספציפית באמצעות הפרמטר hours.

בדוגמה הבאה מופיעה בקשה למידע על התחזית השעתית של שלוש השעות הבאות ב-Mountain View, קליפורניה:

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"

בתגובה, האובייקט interval מציין כל שעה של מידע:

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

ציון מספר השעות להצגה בכל דף

אפשר לציין את מספר שעות הנתונים שיוחזר בכל דף באמצעות הפרמטר pageSize בכתובת ה-URL. ערך ברירת המחדל הוא 24 שעות של מידע על תחזית לכל דף.

תשובות עם כמה דפים של מידע כוללות את הערך nextPageToken. כדי להציג את הדף הבא של המידע, מעבירים את הערך nextPageToken לפרמטר pageToken בבקשה.

בדוגמה הבאה מבקשים נתונים של תחזית מזג האוויר ל-25 שעות עבור 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=25&pageSize=3"

התשובה, שכוללת את שלוש השעות הראשונות של הנתונים, מוצגת בפורמט הבא:

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

כדי לגשת לדף הנתונים הבא, מעבירים את הערך של nextPageToken לפרמטר pageToken בבקשה:

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"

התגובה תהיה בפורמט:

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

נסה בעצמך!

ב-APIs Explorer אפשר לשלוח בקשות לדוגמה כדי להתנסות ב-API ובאפשרויות שלו.

  1. בוחרים בסמל ה-API api בצד שמאל של הדף.

  2. אפשר לערוך את פרמטרים הבקשה.

  3. לוחצים על הלחצן Execute. בתיבת הדו-שיח, בוחרים את החשבון שבו רוצים להשתמש כדי לשלוח את הבקשה.

  4. בחלונית של APIs Explorer, בוחרים בסמל המסך המלא fullscreen כדי להרחיב את החלון של APIs Explorer.