Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2022 Maps & LocationSafari & WebApp Services

WWDC22 · 12 min · Maps & Location / Safari & Web / App Services

Meet WeatherKit

WeatherKit offers valuable weather data for your apps and services to help people stay up to date on the latest conditions. Learn how to use Swift and REST APIs to access information about the current weather, 10-day hourly forecasts for temperature, expected precipitation, wind reports, the UV Index, and more. We’ll also share how WeatherKit can provide timely, hyperlocal weather information without compromising someone’s personal data or their privacy.

Watch at developer.apple.com ↗

Transcript all transcripts

Code shown on screen · 2 snippets

Request the weather in Swift swift · at 4:28 ↗
// Request the weather

import WeatherKit
import CoreLocation


let weatherService = WeatherService()

let syracuse = CLLocation(latitude: 43, longitude: -76)

let weather = try! await weatherService.weather(for: syracuse)

let temperature = weather.currentWeather.temperature

let uvIndex = weather.currentWeather.uvIndex
Request the weather via REST API javascript · at 7:56 ↗
/* Request a token */
const tokenResponse = await fetch('https://example.com/token');
const token = await tokenResponse.text();

/* Get my weather object */
const url = "https://weatherkit.apple.com/1/weather/en-US/41.029/-74.642?dataSets=weatherAlerts&country=US"

const weatherResponse = await fetch(url, {
headers: {
"Authorization": token
}
});
const weather = await weatherResponse.json();

/* Check for active weather alerts */
const alerts = weather.weatherAlerts;
const detailsUrl = weather.weatherAlerts.detailsUrl;

Resources