-
Notifications
You must be signed in to change notification settings - Fork 9
Usage
AlienDwarf edited this page Sep 3, 2022
·
4 revisions
Make sure that you have successfully installed this library as dependency before you start.
using OpenMeteo;
static void Main()
{
RunAsync().GetAwaiter().GetResult();
}
static async Task RunAsync()
{
// Before using the library you have to create a new client. Once created you can reuse it for every other api call you are going to make.
// There is no need to create multiple clients.
OpenMeteo.OpenMeteoClient client = new OpenMeteo.OpenMeteoClient();
// Make a new api call to get the current weather in tokyo
WeatherForecast weatherData = await client.QueryAsync("Tokyo");
// Output the current weather to console
Console.WriteLine("Weather in Tokyo: " + weatherData.CurrentWeather.Temperature + "°C");
}
using OpenMeteo;
static void Main()
{
RunAsync().GetAwaiter().GetResult();
}
static async Task RunAsync()
{
// Before using the library you have to create a new client. Once created you can reuse it for every other api call you are going to make.
// There is no need to create multiple clients.
OpenMeteo.OpenMeteoClient client = new OpenMeteo.OpenMeteoClient();
// Set custom options
WeatherForecastOptions options = new WeatherForecastOptions();
options.Temperature_Unit = TemperatureUnitType.fahrenheit;
options.Latitude = 35.6895f;
options.Longitude = 139.69171f; // For Tokyo
// Make a new api call to get the current weather in tokyo
WeatherForecast weatherData = await client.QueryAsync(options);
// Output the current weather to console
Console.WriteLine("Weather in Tokyo: " + weatherData.CurrentWeather.Temperature + "°F");
}
using OpenMeteo;
static void Main()
{
OpenMeteo.OpenMeteoClient client = new OpenMeteo.OpenMeteoClient();
// Create new geocodingOptions object for Tokyo
GeocodingOptions geocodingData = new GeocodingOptions("Tokyo");
var apiResponse = await client.GetCityGeocodingDataAsync(geocodingData);
var cityData = apiResponse.Locations[0];
Console.WriteLine(cityData.Name + " is a city in " + cityData.Country + " with a population of " + cityData.Population + " people.");
Console.WriteLine(cityData.Name + " coordinates are: " + cityData.Latitude + "/" + cityData.Longitude);
// Output: Tokyo is a city in Japan with a population of 8336599 people.
// Output: Tokyo coordinates are: 35.6895/139.69171
}