Punkt końcowy currentConditions zawiera informacje o aktualnych warunkach pogodowych w konkretnej lokalizacji. Interfejs API zwraca te informacje:
- Opis bieżących warunków pogodowych z odpowiednią ikoną
- Bieżąca temperatura
- Temperatura odczuwalna
- Punkt rosy
- indeks temperatury,
- temperatura odczuwalna;
- Wilgotność względna
- Indeks UV
- Prawdopodobieństwo, odsetek i typ opadów
- Prawdopodobieństwo burz
- Ciśnienie na poziomie morza
- kierunek, prędkość i porywy wiatru
- Widoczność i zachmurzenie
- dane historyczne z ostatnich 24 godzin, w tym zmiany temperatury, maksymalne i minimalne temperatury oraz wielkość opadów;
Narzędzie APIs Explorer umożliwia wysyłanie żądań na żywo, dzięki czemu możesz zapoznać się z interfejsem API i jego opcjami:
Informacje o prośbach o aktualne warunki
Aby uzyskać informacje o obecnych warunkach, wyślij żądanie HTTP GET do:
https://weather.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE
W żądaniu URL parametrów uwzględnij współrzędne szerokości i długości geograficznej lokalizacji.
Przykład żądania aktualnych warunków
W tym przykładzie żądamy informacji o obecnych warunkach w Mountain View w Kalifornii:
curl -X GET "https://weather.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY&location.latitude=37.4220& location.longitude=-122.0841"
Odpowiedź ma postać:
{ "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" } } }
Określanie systemu jednostek
Domyślnie interfejs Weather API zwraca dane w systemie metrycznym. Aby otrzymać dane pogodowe w systemie imperialnym, w żądaniu podaj parametr unitsSystem
.
W tym przykładzie żądamy danych pogodowych dla Mountain View w Kalifornii w jednostkach imperialnych:
curl -X GET "https://weather.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY&location.latitude=37.4220& location.longitude=-122.0841&unitsSystem=IMPERIAL"
Odpowiedź ma postać:
{ "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" } } }
Wypróbuj
Narzędzie APIs Explorer umożliwia wysyłanie przykładowych żądań, dzięki czemu możesz zapoznać się z interfejsem API i jego opcjami.
Po prawej stronie strony kliknij ikonę interfejsu API api.
Opcjonalnie możesz zmodyfikować parametry żądania.
Kliknij przycisk Wykonaj. W oknie wybierz konto, którego chcesz użyć do wysłania prośby.
W panelu narzędzia APIs Explorer kliknij ikonę pełnego ekranu Pełny ekran, aby rozwinąć okno narzędzia APIs Explorer.