Skip to content

Examples

Davide Bassi edited this page Jun 11, 2023 · 5 revisions

Forecast

import com.openmeteo.api.Forecast
import com.openmeteo.api.common.query.City
import com.openmeteo.api.common.time.Timezone

val query = Forecast.Query(
  latitude = City.Amsterdam.latitude,
  longitude = City.Amsterdam.longitude,
  daily = Forecast.Daily { listOf(
    weathercode, sunrise, sunset, temperature2mMax, temperature2mMin
  ) },
  currentWeather = true,
)

Forecast(query).getOrThrow().run {

    println("Coordinates: [ $latitude, $longitude ]")
    currentWeather?.run {
        println("Timestamp:   $time")
        println("Temperature: $temperature°C")
        println("Message:     $weatherCode")
        println("Daylight:    $isDay")
    }

}
Clone this wiki locally